[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can `shuffle-vector' be moved?

From: Stefan Monnier
Subject: Re: can `shuffle-vector' be moved?
Date: Fri, 13 May 2011 11:00:10 -0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>> I don't know where it should live, but cookie1.el doesn't seem like the
>> right place.
>> It should be documented in "(elisp) Vector Functions" as well.
>> Let me know if I should do this, please.
>> Also this loop call from Pascal Bourguignon is a nice CL alternative to
>> `shuffle-vector', though it uses the same algorithm:
>> (defun shuffle (vector)
>> "Re-orders randomly the vector."
>> (loop
>> for i from (1-  (length vector)) downto 1
>> do (rotatef (aref vector i) (aref vector (random i)))))

> Nice.
> Why is this limited to vectors? with elt it could work also with lists.

Its algorithmic performance on lists would be poor (O(N²)).
You want a different algorithm for lists.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]