Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Generating Repeatable Pseudorandom Sequences

by sauoq (Abbot)
on Sep 04, 2002 at 18:33 UTC ( [id://195155]=note: print w/replies, xml ) Need Help??


in reply to Generating Repeatable Pseudorandom Sequences

The default behavior for srand (in newer perls) is to try to give you something much less guessable (via /dev/urandom or a combination of the time, process id, and "some other things.")

You don't need to call it (with newer perls) because it is called the first time you call rand().

If you want the same pseudorandom sequence repeatedly, you can get it by repeatedly seeding the generator with the same value. In other words, srand(1); print rand(3) will always print the same value.

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

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

    No recent polls found