Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

by bunnyman (Hermit)
on Jul 10, 2003 at 14:00 UTC ( #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.

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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-12-04 23:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found