Subject: Re: How Best to Randomize a List?
From: (Rob Warnock)
Date: Thu, 09 Aug 2007 05:06:22 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
are  <> wrote:
| What's a good way to randomize a list?  When I needed to do this
| recently, I resorted to CONSing each list element with a random
| number, sorting by the random numbers and then stripping them back
| out. This works, but doing a sort when all I need is randomization is
| obviously highly inefficient.

I'm not sure what's so "obviously highly inefficient" about a SORT,
since generating the number of good-quality random numbers you will
need for decent randomization is going to be *much* more expensive
than a simple SORT at the end. But if you don't like your method,
then try this:

    (coerce (random-shuffle (coerce your-list 'vector)) 'list))

See the Google Groups archive for ways to implement RANDOM-SHUFFLE
in Common Lisp. [Hint: "Fisher-Yates"...]


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607