Re: Random array (fwd)
17 Dec
2003
17 Dec
'03
11:17 p.m.
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
7686
Age (days ago)
7686
Last active (days ago)
0 comments
1 participants
participants (1)
-
Jim Gillogly