Simple random number generators for uniform and Gaussian distributions. More...

Go to the source code of this file.
Functions | |
| real_t | gasdev (uint64_t *seed) |
| Return a random number from a Gaussian distribution. More... | |
| double | lcg61 (uint64_t *seed) |
| Return a random number from a uniform distribution. More... | |
| uint64_t | mkSeed (uint32_t id, uint32_t callSite) |
| Return a seed suitable for calling lcg61 or gasdev. More... | |
Simple random number generators for uniform and Gaussian distributions.
The generator in lcg61 and the hash in mkSeed aren't really industrial strength, but they're more than good enough for present purposes.
Definition in file random.c.
| real_t gasdev | ( | uint64_t * | seed | ) |
Return a random number from a Gaussian distribution.
Use the Box-Muller method to sample a Gaussian distribution with zero mean and unit variance. To ensure the same input seed always generates the same returned value we do not use the standard technique of saving one of the two generated randoms for the next call.
| [in,out] | seed | Seed for generator. |
Definition at line 21 of file random.c.


| double lcg61 | ( | uint64_t * | seed | ) |
Return a random number from a uniform distribution.
A 61-bit prime modulus linear congruential generator with modulus = 2^61 -1.
| [in,out] | seed | Seed for generator. |
Definition at line 41 of file random.c.

| uint64_t mkSeed | ( | uint32_t | id, |
| uint32_t | callSite | ||
| ) |
Return a seed suitable for calling lcg61 or gasdev.
Forms a 64-bit seed for lcg61 from the combination of 2 32-bit Knuth multiplicative hashes, then runs off 10 values to pass up the worst of the early low-bit correlations.
| [in] | id | An id number such as an atom gid that is unique to each entity that requires random numbers. |
| [in] | callSite | A unique number for each call site in the code that needs to generate random seeds. Using a different value for callSite allows different parts of the code to obtain different random streams for the same id. |
Definition at line 65 of file random.c.

