Random array (fwd)

Jim Gillogly jim at acm.org
Fri Oct 30 11:57:15 PST 1998



> And what's so bad about doing this:
> 
> for (i=0; i < n-1; i++) {
>   swap_positions(array, i, i+rand(n-i));
> }
>
> which populates the array by randomly choosing the next element?

That one's fine, and is equivalent to Knuth's Algorithm P, except
that it does two more additions per iteration.

-- 
	Jim Gillogly
	Trewesday, 9 Blotmath S.R. 1998, 19:16
	12.19.5.11.12, 10 Eb 5 Zac, Seventh Lord of Night






More information about the cypherpunks-legacy mailing list