Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Generating Repeatable Pseudorandom Sequences

by ichimunki (Priest)
on Sep 04, 2002 at 19:02 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found