| Difference Topic NumberDiffRandNum (r1.1 - 24 Aug 2004 - BrentAFulgham) |
| Added: | ||
| > > |
%META:TOPICINFO{author="BrentAFulgham" date="1093388972" format="1.0" version="1.1"}%
Generating Different Random NumbersProblemYou notice that several processes are getting the same "random" number sequence. You would like each process to be receiving its own unique random numbers.SolutionUse therandom:seed function to seed the pseudo-random number generator with a new seed value.
DiscussionThe pseudo-random number generator used in the Erlang implementation defaults to a constant value in the current process dictionary. Consequently, processes that happen to start at the same time could potentially seed with the same value. Using therandom:seed function allows you to modify this default behavior.
Seeding a pseudo-random number generator sets its internal state deterministically. Seeding a generator with a particular number forces it to produce a sequence of pseudo-random numbers that is the same across runs and across platforms. This could be useful if you wish to provide the illusion of randomness.
See Also
| |