Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Generating Repeatable Pseudorandom Sequences

by sauoq (Abbot)
on Sep 04, 2002 at 18:33 UTC ( #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? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2023-02-09 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (44 votes). Check out past polls.

    Notices?