🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #20

Re: random number generator

#20
From: Jerry Coffin
Date: Tue, 03 Jun 2003 18:24
25 lines
2193 bytes
In article <SikCa.1506$Z83.788@wagner.videotron.net>, fw1803
@videotron.ca says...
> Hi, for a lotto program I'm working on I want to code a random number
> generator *but*  numbers generated must be always different.

That's not a random number generator, but a random _sample_ generator.  
Chapter 13 (column 13) of _More Programming Pearls_ is devoted to this 
particular problem.  (By Jon Bentley, published by Addison-Wesley, ISBN 
0-201-118899-0).  I'm not sure, but I seem to recall there being a newer 
Programming Pearls book which may contain an (updated version of) this 
as well -- by my memory's far from dependable on subjects like this.

> ok so we can forget the rand() funtion (please don't tell me to code a
> routine that checks numbers generated and if they repeat re-draw a number,
> bad performance code...)

Robert Floyd has designed a deceptively simple looking algorithm that 
produces correct results while still only calling rand once for each 
output number created.  It's outlined in the book above.

-- 
    Later,
    Jerry.

The universe is a figment of its own imagination.
Technical Details
Message-ID: <MPG.194695f039046fcc989a30@news.clspco.adelphia.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!router1.news.adelphia.net!news1.news.adelphia.net.POSTED!not-for-mail
References: <SikCa.1506$Z83.788@wagner.videotron.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1014db,da54b5a763359bc3
X-Google-Attributes: gid1014db,public
X-Google-Thread: 109fba,da54b5a763359bc3
X-Google-Attributes: gid109fba,public
X-Google-Thread: 10d4ba,da54b5a763359bc3
X-Google-Attributes: gid10d4ba,public
X-Google-ArrivalTime: 2003-06-03 11:24:42 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!router1.news.adelphia.net!news1.news.adelphia.net.POSTED!not-for-mail
From: Jerry Coffin <jcoffin@taeus.com>
Newsgroups: att.lang.c++,comp.lang.c,comp.lang.c++
Subject: Re: random number generator
Message-ID: <MPG.194695f039046fcc989a30@news.clspco.adelphia.net>
References: <SikCa.1506$Z83.788@wagner.videotron.net>
Organization: TAEUS
X-Newsreader: MicroPlanet Gravity v2.50
Lines: 25
Date: Tue, 03 Jun 2003 18:24:41 GMT
NNTP-Posting-Host: 68.71.49.73
X-Complaints-To: abuse@adelphia.net
X-Trace: news1.news.adelphia.net 1054664681 68.71.49.73 (Tue, 03 Jun 2003 14:24:41 EDT)
NNTP-Posting-Date: Tue, 03 Jun 2003 14:24:41 EDT