Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Generating Repeatable Pseudorandom Sequences

by ichimunki (Priest)
on Sep 04, 2002 at 19:02 UTC ( #195165=note: print w/ replies, xml ) Need Help??


in reply to Generating Repeatable Pseudorandom Sequences

On 2nd thought:
dws is right, you need to use a module or something, since the approach I list below is probably not thread-safe.

You have the right idea, when you want to generate a sequence reliably, use srand($seed), keeping $seed consistent across calls to srand. Each time you call srand() this resets the random number generator. If you want to "clear" the random number generator for more random usage, just call srand() with no seed.

#!/usr/bin/pseudocode srand($seed); print rand, rand, rand -> 1, 2, 3 srand($seed); print rand, rand, rand -> 1, 2, 3 srand(); print rand, rand, rand -> 42, 256, 3.14 srand($seed); print rand, rand, rand -> 1, 2, 3


Comment on Re: Generating Repeatable Pseudorandom Sequences
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://195165]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-09-19 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (145 votes), past polls