next up previous contents index
Next: Basic urand algorithm not Up: Problems with the basic Previous: Problems with the basic   Contents   Index

Basic urand objects are not independent

Because the basic urand class uses the underlying Unix rand() call, objects of type urand are not independent. Rather, they effectively refer to the same object. Setting the seed on one object of this class sets the seed for all objects of that class.

If for example, one wants to perform simulations in parallel, and compare results with different numbers of threads, then the simplest way of arranging this is to ensure that each object in the simulation requiring random numbers gets its own unique stream of random numbers. This can be done by assigning a different urand object to each simulation object, and giving them a distinct seed. Then no matter what the distribution of objects over threads are, the sequence random numbers will be the same from simulation to simulation, allowing meaningful comparisons. The UNURAN and GNUSL libraries both provide independently streamed random numbers.



Russell Standish 2016-09-02