Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 chanting in the Monastery: (5)
As of 2014-07-14 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (253 votes), past polls