code_junkie

What's the efficiency and quality of this shuffling algorithm?

Nov 13th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. @shuffled = sort { rand() <=> rand() } @array;
  2.  
  3. $ perldoc List::Util
  4. ⋮
  5. shuffle LIST
  6. Returns the elements of LIST in a random order
  7.  
  8. @cards = shuffle 0..51 # 0..51 in a random order
  9. ⋮
  10.  
  11. @shuffled = map {
  12. $_->[1]
  13. } sort {
  14. $a->[0] <=> $b->[0]
  15. } map {
  16. [ rand(), $_ ]
  17. } @array;
Add Comment
Please, Sign In to add comment