in reply to A reproducible shuffle? ("stable shuffle")
use strict; use warnings; use List::Util qw(shuffle); sub my_shuffle { my $old_seed = rand(2**32); srand(1); my @shuffled = shuffle(@_); srand($old_seed); return @shuffled; } print my_shuffle(qw(a b c d e f g)), $/; print my_shuffle(qw(a b c d e f g)), $/; print my_shuffle(qw(a b c d e f g)), $/;
Actually I'm not sure if the reseeding is done correctly.
Another possibility is to take List::Util's shuffle, and replace calls to rand with your own pseudo-random number generator, that you can keep separate from rand.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A reproducible shuffle? ("stable shuffle")
by AK108 (Friar) on Feb 04, 2008 at 17:40 UTC | |
by moritz (Cardinal) on Feb 04, 2008 at 17:53 UTC |