Random Numbers

Generating good quality random numbers is crucial for any Monte Carlo code. In addition to generating pseudo random numbers with good statistics and in minimal CPU time, we also have the requirement that computations should be reproducible and the random number sequences independent on each worker when the code runs in parallel mode.

We define the random number generator in the module ConsistentRNG.jl, which is loaded onto each process. Furthermore, independent seeds are used to seed the RNGs on each worker (from goQMC.jl). These seeds are generated using the Random.RandomDevice random number generator, which draws entropy from the operating system / hardware. The seeds are saved to file with a filename that includes the number of processes used. If a suitable file is found, then seeds are read in from the file. This behaviour can be controlled by the flag reuseRandomSeeds in the input file.

For the random number generator we are currently using 'Xoroshiro128Plus' from 'RandomNumbers.jl'. For benchmarks and statistical test results see the Documentation of RandomNumbers.jl.

Module ConsistentRNG.jl

Rimu.ConsistentRNG.CRNGsConstant
CRNGs[]

Defines an array of random number generators suitable for threaded code. For MPI or distributed runs it should be seeded separately on each process with seedCRNG!. Currently we are using 'Xoshiro256StarStar' from 'RandomNumbers.jl', see the Documentation and this Blog post. In order to change the random number generator, edit 'ConsistentRNG.jl'.

rng = CRNGs[][Threads.threadid()]
rand(rng)
source
Rimu.ConsistentRNG.CRNGType

Baseline random number generator used throughout. Currently we are using 'Xoshiro256StarStar' from 'RandomNumbers.jl', see the Documentation and this Blog post. In order to change the random number generator, edit 'ConsistentRNG.jl'.

source
Rimu.ConsistentRNG.cRandMethod
r = cRand(args...)

Similar to 'rand(args)' but uses consistent random number generator 'CRNGs[]'. 'cRand()' generates a single uniformly distributed random number in the interval [0,1). Currently we are using 'Xoshiro256StarStar' from 'RandomNumbers.jl', see the Documentation and this Blog post.

source
Rimu.ConsistentRNG.cRandnMethod
r = cRandn(args...)

Similar to 'randn(args)' but uses consistent random number generators 'CRNGs[]'. 'cRandn()' generates a single normally distributed random number. Currently we are using 'Xoshiro256StarStar' from 'RandomNumbers.jl', see the Documentation and this Blog post.

source
Rimu.ConsistentRNG.check_crng_independenceMethod
ConsistentRNG.check_crng_independence(v)

Primitve test to check the random number generators. It throws an error if some of the threaded random number generators are equal. Returns the number of threaded RNGs.

source
Rimu.ConsistentRNG.newChildRNGFunction
newChildRNG(parent_rng = trng())

Random number generator that is seeded deterministically from the thread-consistent global rng trng(). By scrambling with hash(), a statistically independent pseudo-random sequence from the parent rng is accessed.

source
Rimu.ConsistentRNG.seedCRNG!Method
seedCRNG!([seed])

Seed the threaded consistent random number generators CRNGs[]. If a single number is given, this will be used to seed a random sequence, which is hashed and then used to generate seeds for each rng in the vector CRNGs. When no argument is given, each rng is seeded randomly.

source