[104888] in Cypherpunks
Re: Random array (fwd)
daemon@ATHENA.MIT.EDU (Jim Gillogly)
Fri Oct 30 14:41:06 1998
Date: Fri, 30 Oct 1998 11:18:10 -0800
From: Jim Gillogly <jim@acm.org>
To: Cypherpunks Distributed Remailer <cypherpunks@EINSTEIN.ssz.com>
Reply-To: Jim Gillogly <jim@acm.org>
> 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