LibCapy - random

Pseudo random generation class.

Macros:

Enumerations:

Type of PRNG algorithms supported by CapyRandom

Typedefs:

Type for the seed of a CapyRandom

Type for the state of a CapyRandom

Struct CapyRandom :

Struct CapyRandom's properties:

Type of algorithm (default: capyRandomPrng_pcg_xsh_rr)

Seed

State

Random bits

Buffer for optimisation

Struct CapyRandom's methods:

Destructor

Step the state

Set the type of PRNG

Input argument(s):

type: type of PRNG

Output and side effect(s):

The type is updated and the CapyRandom is re-initialised.

Return the next pseudo random number as a boolean

Output and side effect(s):

Return the random number as a boolean

Return the next pseudo random number as an integer using the xorshift algorithm

Output and side effect(s):

Return the random number as an integer

Return the next pseudo random number as a double using the Downey algorithm

Output and side effect(s):

Return the random number as a double in [0.0, 1.0]

Return the next pseudo random number as a double using integer division

Output and side effect(s):

Return the random number as a double in [0.0, 1.0]. It is around two times faster than the Downey's algorithm but generates random floating-point number less efficiently. See https://baillehachepascal.dev/2021/random_float.php

Return the next pseudo random number as an integer mapped into a range

Input argument(s):

range: the range to map the random number to

Output and side effect(s):

Return the random number as an integer in the given range, bounds are inclusive

Return the next pseudo random number as an integer mapped into a range using Lemire's algorithm

Input argument(s):

range: the range to map the random number to

Output and side effect(s):

Return the random number as an integer in the given range, bounds are inclusive

Return the next pseudo random number as a double mapped into a range

Input argument(s):

range: the range to map the random number to

Output and side effect(s):

Return the random number as a double in the given range, bounds are inclusive

Return the next pseudo random number as a CapyRatio

Output and side effect(s):

Return a random CapyRatio in [0.0, 1.0]

Get a pseudo-random uint32_t using the Squirrel3 algorithm.

Input argument(s):

position: the position in the pseudo-random sequence

Output and side effect(s):

Return the pseudo-random uint32_t at the given position in the sequence. Note that this sequence is different from the one generated by the other methods of CapyRandom. Note also that the sequence is completely determined by the seed of the CapyRandom.

Get a random event in a statistical distribution

Input argument(s):

dist: the distribution

Output and side effect(s):

Return a distribution event

Functions:

Create a CapyRandom

Input argument(s):

seed: seed of the generator

Output and side effect(s):

Return a CapyRandom

Allocate memory for a new CapyRandom and create it

Input argument(s):

seed: seed of the generator

Output and side effect(s):

Return a CapyRandom

Exception(s):

May raise CapyExc_MallocFailed.

Free the memory used by a CapyRandom* and reset '*that' to NULL

Input argument(s):

that: a pointer to the CapyRandom to free

Get a truly random value to seed a random generator

Output and side effect(s):

Return the truly random value.