1998-10-30 - Re: Random array (fwd)

Header Data

From: Jim Gillogly <jim@acm.org>
To: Cypherpunks Distributed Remailer <cypherpunks@EINSTEIN.ssz.com>
Message Hash: d1a698b52bf73939e7c1e7682b044434bf06f787f34419ee576fdeac41d5c0f2
Message ID: <363A10F2.D5AABA72@acm.org>
Reply To: N/A
UTC Datetime: 1998-10-30 19:57:15 UTC
Raw Date: Sat, 31 Oct 1998 03:57:15 +0800

Raw message

From: Jim Gillogly <jim@acm.org>
Date: Sat, 31 Oct 1998 03:57:15 +0800
To: Cypherpunks Distributed Remailer <cypherpunks@EINSTEIN.ssz.com>
Subject: Re: Random array (fwd)
Message-ID: <363A10F2.D5AABA72@acm.org>
MIME-Version: 1.0
Content-Type: text/plain



> 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





Thread