Squares RNG#
Implements the Squares RNG generator [[1]]. Based on:
Contrary to the other PRNG generators, the seed of this generator has to be chosen more carefully. Two ways to initialize the generator are implemented:
supply a seed between 0 and 29. This will initialize the generator with a specific key from the list supplied by the author of the algorithm. I.e., seed=3 takes the 3. seed in the author’s key list.
Supply a specific seed that is larger than 30. In this case, the supplied seed is used as a key. Only use keys that match the properties outlined in [[1]], using seeds from the algorithm’s author is recommended (25,000 different seeds are supplied in
keys.havailable at https://squaresrng.wixsite.com/rand).
Distribution#
The following figure shows an example distribution generated using the Squares PRNG. Additionally, the histogram of the generated values is shown.
(Source code, png, hires.png, pdf)
Fig. 337 Distribution generated using the Squares PRNG using seed 0.#
Reference#
-
typedef struct uz_prng_squares_t uz_prng_squares_t#
Object of Squares generator.
-
uz_prng_squares_t *uz_prng_squares_init(uint64_t key)#
Initializes the Squares random number generator.
- Parameters:
key – Values 0-29 choose a key from https://squaresrng.wixsite.com/rand. Values >30 are directly set as key, only supply properly calculated custom key’s.
- Returns:
uz_prng_squares_t*
-
uint32_t uz_prng_squares_get_uniform_uint32(uz_prng_squares_t *self)#
Returns a uniformly distributed unsigned integer within 0…UINT32_MAX (i.e., 2^32-1=4,294,967,295)
- Parameters:
self
- Returns:
uint32_t
-
void uz_prng_squares_reset(uz_prng_squares_t *self, uint64_t key)#
Resets generator to key.
- Parameters:
self
key