A couple of days ago, I had the need to quickly randomize the order of an array. I crafted the following snippet, based in a Schwartzian Transform...
@list = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, rand +] } @list;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Schwartzian transform for randomizing a list
by Aristotle (Chancellor) on Jan 02, 2004 at 14:03 UTC | |
|
Re: Schwartzian transform for randomizing a list
by RMGir (Prior) on Jan 02, 2004 at 18:08 UTC | |
|
Re: Schwartzian transform for randomizing a list
by fokat (Deacon) on Jan 02, 2004 at 18:41 UTC |