A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove

random

Utilities for producing random numbers.

____________________________________________________________________________________________________

random

The base class for all 32 bit random number generators.

If ETL_POLYMORPHIC_RANDOM is defined, then the base class will have the following members, otherwise the base is
empty.

virtual ~random();
virtual void initialise(uint32_t seed) = 0;
virtual uint32_t operator()() = 0;
virtual uint32_t range(uint32_t low, uint32_t high) = 0;

____________________________________________________________________________________________________

random_xorshift

Uses a 128bit XOR shift algorithm for producing a pseudo-random sequence of integers.
The result is a 32 bit integer between 0 and 4,294,967,295 (2^32 - 1).

random_xor_shift()

Constructor.
Uses the address of the object as the seed for the sequence.

random_xor_shift(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

uint32_t operator()()

Returns the next number in the pseudo-random sequence.

uint32_t range(uint32_t low, uint32_t high)

Returns a number between the specified ranges, inclusive.

____________________________________________________________________________________________________

random_lcg

Generates a 32 bit pseudo-random number using a linear congruent generator.
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).

____________________________________________________________________________________________________
random_lcg()

Constructor.
Uses the address of the object as the seed for the sequence

____________________________________________________________________________________________________
random_lcg(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

____________________________________________________________________________________________________
void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

____________________________________________________________________________________________________
uint32_t operator()()

Returns the next number in the pseudo-random sequence.

____________________________________________________________________________________________________
uint32_t range(uint32_t low, uint32_t high)

Returns a number between the specified ranges, inclusive.

____________________________________________________________________________________________________

random_clcg

Generates a 32 bit pseudo-random number using a combined linear congruent generator.
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).

____________________________________________________________________________________________________
random_clcg()

Constructor.
Uses the address of the object as the seed for the sequence.

____________________________________________________________________________________________________
random_clcg(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

____________________________________________________________________________________________________
void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

____________________________________________________________________________________________________
uint32_t operator()()

Returns the next number in the pseudo-random sequence.

____________________________________________________________________________________________________
uint32_t range(uint32_t low, uint32_t high)
Returns a number between the specified ranges, inclusive.

____________________________________________________________________________________________________

random_lsfr

Generates a 32 bit pseudo-random number using a linear shift feedback register.
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
The seed must not be zero. The output does not include zero.

____________________________________________________________________________________________________
random_lsfr()

Constructor.
Uses the address of the object as the seed for the sequence.

____________________________________________________________________________________________________
random_lsfr(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

____________________________________________________________________________________________________
void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

____________________________________________________________________________________________________
uint32_t operator()()

Returns the next number in the pseudo-random sequence.

____________________________________________________________________________________________________
uint32_t range(uint32_t low, uint32_t high)

Returns a number between the specified ranges, inclusive.

____________________________________________________________________________________________________

random_mwc

Generates a 32 bit pseudo-random number using a multiply-with-carry algorithm.
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).

____________________________________________________________________________________________________
random_mwc()

Constructor.
Uses the address of the object as the seed for the sequence.

____________________________________________________________________________________________________
random_mwc(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

____________________________________________________________________________________________________
void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

____________________________________________________________________________________________________
uint32_t operator()()

Returns the next number in the pseudo-random sequence.

____________________________________________________________________________________________________
uint32_t range(uint32_t low, uint32_t high)

Returns a number between the specified ranges, inclusive.

____________________________________________________________________________________________________

random_pcg

Generates a 32 bit pseudo-random number using a  permuted congruential generator algorithm.
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).

____________________________________________________________________________________________________
random_pcg()

Constructor.
Uses the address of the object as the seed for the sequence.

____________________________________________________________________________________________________
random_pcg(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

____________________________________________________________________________________________________
void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

____________________________________________________________________________________________________
uint32_t operator()()

Returns the next number in the pseudo-random sequence.

____________________________________________________________________________________________________
uint32_t range(uint32_t low, uint32_t high)

Returns a number between the specified ranges, inclusive.

____________________________________________________________________________________________________

random_hash


template <typename THash>
Generates a 32 bit pseudo-random number by applying a user supplied 32bit hash to a counter.
The hash must implement void add(uint8_t) and uint8_t value() member functions.
____________________________________________________________________________________________________
random_hash()

Constructor.
Uses the address of the object as the seed for the sequence.

____________________________________________________________________________________________________
random_hash(uint32_t seed)

Constructor.
Uses seed as the seed for the sequence.

____________________________________________________________________________________________________
void initialise(uint32_t seed)

Sets the seed as the new seed for the sequence.

____________________________________________________________________________________________________
uint32_t operator()()

Returns the next number in the pseudo-random sequence.

____________________________________________________________________________________________________
uint32_t range(uint32_t low, uint32_t high)

Returns a number between the specified ranges, inclusive.
random.h