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

You are incorrect, the routine leaves open the possibility of keeping an item in place. Note the line next if ... there. In fact, as I recall it, that shuffle can be shown to have an even chance of producing any permutation with a true random source and is pretty damn good even with a really BAD random source.

Also, the rand trick you employ can exit early and leave chunks untouched. sortrather relies on consistency, if b>a and c>b then c>a should be implied. If I read the sort code right, violating that could lead to serious goofs like potentially never ending and such.

--
$you = new YOU;
honk() if $you->love(perl)

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

Replies are listed 'Best First'.
Re: Re: Re: Re: help in understanding the standard array shuffle
by kschwab (Vicar) on Feb 14, 2001 at 19:59 UTC
    All valid comments, but my reply wasn't to the original node, it was to Gloom's node, which was suggesting @array = sort { (-1,1)[int rand 2] } @array;.

    In any case, I was nitting on the lack of a 0 return, which in light of your comments, matters little. (since random results from a sort sub are bad news...)

      Sorry, and of course merlyn said it better at the right depth. =) (You are right tho, to get the evil way correct, adding 0 to the mix would be necessary...)

      --
      $you = new YOU;
      honk() if $you->love(perl)