in reply to Re: help in understanding the standard array shuffle
in thread help in understanding the standard array shuffle

The sort order is required to be 'consistent': that is, if A > B and B > C, then when asked about A and C, you'd better durn well return A > C. The underlying qsort(3) function demands it, and was optimized for it.

Because your randomizing function has no memory to guarantee this consistency, you'll be very surprised by the behavior. Older qsort functions would in fact dump core or lose data on this kind of pseudo-shuffle. Modern perls use an internal sort function that at least doesn't lose the data, but it's really not the way to do a shuffle nicely. See the FAQ solution instead, quoted at the head of this thread.

-- Randal L. Schwartz, Perl hacker

  • Comment on Re: Re: help in understanding the standard array shuffle