Turns out this is in perlfaq4 (on Unix - I imagine it is somewhere in the MacPerl docs too).
But I'm glad you asked, because I recently implemented a less efficient version, and I'll
just go and fix that.


By the way, depending on the nature of your experiments, mainly N and the number of
repetitions you are running, you may need to consider a better random function than
the supplied one: for example, there was an interesting discussion of computerized
card shuffling on the "fun with perl" list a few years ago - a random generator with a 32
bit seed will generate only a small fraction of all possible orders of a deck of cards. Most
people don't play 2 billion games of cards - but in some experimental situations this may
be a real limitation. Here is a link to the top of the thread


http://bumppo.net/lists/fun-with-perl/2000/07/msg00006.html

BTW, I tested the SchwartzianTransform sort used by Amir against the Fisher-Yates
below, and for N between 1000 and 100000, ST was 5 - 6 times slower than FY, and
does not scale linearly where FY does. I guess this should have been obvious since
the ST version does an 'extra' sort. I can't comment on whether one gives a more 'random'
result than the other.


I had some trouble with my mailer, and just saw that someone else posted Fisher-Yates,
so I clipped it from here. But I decided to send the rest of the discussion in the hopes that
even if it is a bit off-topic, it is relevant enough, and maybe even interesting.


On Wednesday, February 26, 2003, at 04:43 PM, Nicholas G. Thornton wrote:


I was wondering how I would go aboput randomly ordering N number of things. I'm
running an experiment and I want to randomize the order things appear in.


~wren



Reply via email to