in reply to Generating Random Integers
A key point is the generation of the seed value... Here is a seed
value creation that I got out of a book.
/me not a math guru
to develop seed stuff :)
srand( (time() ^ (time() % $]) ) ^ exp(length($0))**$$);
This snippet is taken from "Perl, The Complete Reference" by Martin C. Brown, published by Osborne pp. 90-91
Update: Why is choosing a unique seed important? rand() generates a sequence of pseudo-random numbers. This implies that the sequence of generation could possibly be predictable or duplicated. A potentially bad situation for an application that requires security.
Intelligent seed generation helps to make that duplication or prediction difficult. That is why good seeds incorporate the use of time() and the current process id, $$.
I've seen other functions that generate the seed value based on prime numbers and other such black magic.... :)
|
---|
Replies are listed 'Best First'. | |
---|---|
(tye)Re: Generating Random Integers
by tye (Sage) on Jan 03, 2001 at 21:08 UTC | |
by fongsaiyuk (Pilgrim) on Jan 03, 2001 at 21:29 UTC | |
by tye (Sage) on Jan 03, 2001 at 21:34 UTC | |
Re: Re:(fongsaiyuk) Generating Random Integers
by salvadors (Pilgrim) on Jan 03, 2001 at 20:31 UTC | |
by fongsaiyuk (Pilgrim) on Jan 03, 2001 at 20:38 UTC |