Subject: | |
From: | |
Reply To: | |
Date: | Fri, 14 Jan 2000 02:11:51 GMT |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Porter, Allen H ([log in to unmask]) wrote:
: I have a very large ASCII file (270 bytes per record with approx. 1,000,000
: records) that needs to be randomized. The current program we are using
: takes a couple of hours to run. Does anyone have a faster method?
I don't know if it would be faster, but here is one way to produce
a random permutation. Suppose you have t records, numbered 1
through t.
1. Set j = t.
2. Generate a random number k in the range 1 through j.
3. Exchange record k and record j.
4. Subtract 1 from j. If j > 1 go to step 2.
This is based on Algorithm P (Shuffling) in 3.4.2, Random Sampling
and Shuffling, in Knuth, The Art of Computer Programming, Volume 2,
Seminumerical Algorithms.
Walter Murray
|
|
|