[Small-cl-src] shuffle-vector

Ben Hyde bhyde at pobox.com
Thu Jun 24 15:03:50 UTC 2004


(defun shuffle-vector (v)
   "Return copy of vector with elements shuffled like a deck of cards."
   (loop
     with result = (copy-seq v)
     finally (return result)
     for i from (length v) downto 1
     as j = (random i)
     do (rotatef (svref result j) (svref result (1- i)))))


That was fun.





More information about the Small-cl-src mailing list