Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shuffle: influence of sort

Does the line with the sort result in a more random array or is the sort here only a waste?

use List::Util qw(shuffle);


@random1 = shuffle sort keys %vocables;

@random2 = shuffle keys %vocables;
like image 256
sid_com Avatar asked Jan 23 '12 13:01

sid_com


1 Answers

If placing a sort before the shuffle made a difference, then shuffle would be broken. Since shuffle works, the sort is a waste of processor time. The whole point of a good shuffle is to eliminate any pre-existing ordering of the elements.

like image 136
Eric Strom Avatar answered Oct 18 '22 20:10

Eric Strom