Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I should have been less cavalier. The generation of random numbers is too important to be left to chance, as they say. One of the desirable features of PRNGs is that they have a provably long period before they start repeating themselves. By reseeding this way, you lose that. After a large number of iterations, you might end up in a short limit cycle of possible values for the next seed. That will depend on the details of your rand() and exactly how many times you call it per loop. So I'm afraid I have to take back my advice. Don't reseed this way, epecially if you're going to do a lot of loops.

You could use rand() with the initial seed to generate all the other seeds you need. You'd either have to know the number of loops ahead of time, or keep winding rand() forward from the initial seed.

The best solution would be to use a different random number generator that lets you get at the current seed value. There are several available. They're also easy to write -- just don't try to pick the constants yourself.


In reply to Re: Re: Can I seed srand() with results from rand()? by no_slogan
in thread Can I seed srand() with results from rand()? by blokhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-12-02 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?