Mail Archives: djgpp/1997/08/10/18:48:18
On 7 Aug 1997 06:44:25 GMT, Paul Derbyshire <ao950 AT FreeNet DOT Carleton DOT CA> 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
- Raw text -