From: p DOT steiner AT t-online DOT de (Peter Steiner) Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie Question: Random Numbers Date: 7 Aug 1997 13:58:55 GMT Organization: Telekom Online Internet Gateway Lines: 49 Message-ID: <5sckav$i2o$5@news01.btx.dtag.de> References: <01bc9a61$57701640$204678c7 AT warren1> <33E839E3 DOT 38A0E28D AT alcyone DOT com> <5sbqs9$jrj AT freenet-news DOT carleton DOT ca> Reply-To: p DOT steiner AT t-online DOT de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On 7 Aug 1997 06:44:25 GMT, Paul Derbyshire wrote: > >Erik Max Francis (max AT alcyone DOT com) writes: >> Warren Smith wrote: >> >>> How can I get a truly random number (w/o the same sequence of numbers >>> appearing over and over)? >> >> This is fundamentally impossible with a computer without some strange >> peripherals, because computers are designed to be deterministic. >> >> There are many, many books written about "pseudorandom numbers," as >> they'er called. There's a whole chapter (chapter 7) in _Numerical >> recipes_, for instance, devoted to this subject. > >A URL would be nice. (Preferably for the main page, chapter 7 is probably >easily tracked down from there.) Just the name of a site or document by >itself isn't helpful, because it has to be put into a search engine which >will find ten thousand irrelevant sites. Mostly commercial sites. I think >that most of the search engines accept money under the table from big >companies to make their sites pop up at the top of every search someone >does that is in any way slightly connected to their products. :P Look in the Linux sources in drivers/char/random.c That's a really strong random number generator. For quick 16-bit pseudo random numbers try: int rand = rand_seed; int random(void) { rand=rand * 58321 + 11113; return (rand >> 16); } I use this to generate nice white noise. It has a wonderful spectrum. You can use different prime-numbers in the function and improve it by switching to long long but this requires full 32-Bit primes. The rand_seed may be generated using time and date. And then no sequence will appear over and over. Bye, Peter Steiner -- _ x ___ / \_/_\_ /,--' p DOT steiner AT t-online DOT de (Peter Steiner) \/>'~~~~// \_____/ signature V0.2 alpha