Subject: Better implementation of random_permutation
From: Mark H Weaver
Date: Thu, 20 Jan 2011 17:54:43 -0500
Robert Dodier <robert.dodier at gmail.com> writes:
> Hmm, this is the same Knuth shuffle expressed in a different way,
> right?
It's the slightly more efficient "inside-out" variant of the Knuth
shuffle, a.k.a. Fisher-Yates shuffle.
> If so the only problem I see is that the random numbers should
> come from Maxima's $RANDOM and not CL RANDOM
Oops, good catch! Unfortunately, $RANDOM is much slower than CL RANDOM.
On my machine, it's about 37 times slower.
When using $RANDOM, my new $RANDOM_PERMUTATION is only faster on my
machine for lists with hundreds of elements:
For size 10000, it's faster: ratio=5.15
For size 1000, it's faster: ratio=1.23
For size 100, it's slower: ratio=0.95
For size 10, it's slower: ratio=0.93
Mark