Saturday, April 5, 2008

An Elegant Shuffle Redux

Gary King has posted his reaction to Leslie's shuffle algorithm. As always, his comments are very relevant.

I feel remiss for not posting a copy of Leslie's code here, so here it is:

(defun seqrnd (seq)
"Randomize the elements of a sequence. Destructive on SEQ."
(sort seq #'< :key (lambda (x) (random 1.0))))
How elegant!

No comments: