Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One of the reasons for having a random number generator (RNG) require instantiation is so that it can keep its state internal, that way in a multi-threaded application you don't introduce non-determinism when multiple threads use the same RNG with process-global state. Suppose you have two threads, each working on independent parts of a problem - if the state (seed) is private to the RNG instance then you can have determinism when you seed each thread's RNG with a known value. On the other hand, if the RNG keeps state in a global variable then the sequence of random numbers observed by each thread depends on the inter-leaving of their calls to the RNG - you've now introduced non-determinism.</p> <p>One programming pattern that is used to assign work in multi-threaded applications is a <a href="http://en.wikipedia.org/wiki/Thread_pool_pattern" rel="nofollow noreferrer">thread pool</a>. If the work items that are queued up for worker threads in the pool to execute require an RNG and you want execution to be deterministic from run to run, then you want each thread to re-seed the RNG after pulling a new work item from the queue</p> <ul> <li>this can be done as part of the initialization for the work item</li> <li>the seed might involve a <a href="http://en.wikipedia.org/wiki/Hash_function" rel="nofollow noreferrer">hash function</a> of parameters for the job</li> <li>if you are careful about how this is coded you can have pseudo-randomness and determinism regardless of the number of worker threads or the order in which they pull jobs off the queue.</li> </ul> <p>Here's an SO question that deals with this: <a href="https://stackoverflow.com/questions/6467585/deterministic-random-number-generator-tied-to-instance-thread-independent">Deterministic random number generator tied to instance (thread independent)</a></p> <p>In a single-threaded application it is not necessary to re-seed an RNG, and in fact it is undesirable because by doing that you shorten it's cycle before it will start repeating. The exception to this is what @MatthewSanders pointed out, Cryptography - in that case you want maximum entropy (least determinism) because random numbers are used as private keys.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload