Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Can I seed srand() with results from rand()?

by bunnyman (Hermit)
on Jul 10, 2003 at 14:00 UTC ( [id://272972]=note: print w/replies, xml ) Need Help??


in reply to Can I seed srand() with results from rand()?

The process starts with a random seed that I provide, so that I can reproduce interesting results later.

The code you provided will make it hard for you to reproduce the results later.

The only thing that is predictable about rand() is that given the exact same input to srand(), you will get the exact same outputs from rand() every time you do it.

So:
srand(42) -> 78, 102, 4, 19, ...
srand(55) -> 8, 2, 66, 243, ...

There isn't anything wrong with calling srand() more than once, except that doing so will not make the output more random, it may even make it less random.

To reproduce the same outputs from rand(), you will have to call srand() with the same inputs in the same order every time, so this is a new part of state that you must save. On top of that, if the implementation of rand() changes in different versions of perl, you will not reproduce the same results on different versions.

  • Comment on Re: Can I seed srand() with results from rand()?

Log In?
Username:
Password:

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

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

    No recent polls found