HP3000-L Archives

January 2000, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Walter Murray <[log in to unmask]>
Reply To:
Date:
Fri, 14 Jan 2000 02:11:51 GMT
Content-Type:
text/plain
Parts/Attachments:
text/plain (20 lines)
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

ATOM RSS1 RSS2