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

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2016-10-22 10:04 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (294 votes). Check out past polls.