YAKL
Classes | Public Member Functions | List of all members
yakl::Random Class Reference

Non-cryptographic pseudo-random number generator with a very small internal state. More...

#include <YAKL_random.h>

Public Member Functions

YAKL_INLINE Random ()
 Initializes a prng object with the seed 1368976481. Warm-up of 20 iterations. More...
 
YAKL_INLINE Random (Random &&in)
 Moves a Random object. More...
 
YAKL_INLINE Random (Random const &in)
 Copies a Random object. More...
 
YAKL_INLINE Random (u8 seed)
 Initializes a prng object with the specified seed. Warm-up of 20 iterations. More...
 
YAKL_INLINE u8 gen ()
 Generates a random unsigned integer between zero and std::numeric_limits<u8>::max() - 1 More...
 
template<class T >
YAKL_INLINEgenFP ()
 Generates a random floating point value between 0 and 1 More...
 
template<class T >
YAKL_INLINEgenFP (T lb, T ub)
 Generates a random floating point value between lb and ub More...
 
YAKL_INLINE Randomoperator= (Random &&in)
 Moves a Random object. More...
 
YAKL_INLINE Randomoperator= (Random const &in)
 Copies a Random object. More...
 
YAKL_INLINE void set_seed (u8 seed)
 Assigns a seed. Warm-up of 20 iterations. More...
 

Detailed Description

Non-cryptographic pseudo-random number generator with a very small internal state.

Based on the algorithm here: https://burtleburtle.net/bob/rand/smallprng.html The author wrote the following statement on the website (Accessed Aug 1 2022):

I wrote this PRNG. I place it in the public domain. Same goes for at least the implementation of all those tests linked to above.

IMPORTANT: When creating a Random object inside a parallel_for kernel, please ensure each thread's object has a different and unique initial seed.

Constructor & Destructor Documentation

◆ Random() [1/4]

YAKL_INLINE yakl::Random::Random ( )
inline

Initializes a prng object with the seed 1368976481. Warm-up of 20 iterations.

◆ Random() [2/4]

YAKL_INLINE yakl::Random::Random ( u8  seed)
inline

Initializes a prng object with the specified seed. Warm-up of 20 iterations.

◆ Random() [3/4]

YAKL_INLINE yakl::Random::Random ( Random const &  in)
inline

Copies a Random object.

◆ Random() [4/4]

YAKL_INLINE yakl::Random::Random ( Random &&  in)
inline

Moves a Random object.

Member Function Documentation

◆ gen()

YAKL_INLINE u8 yakl::Random::gen ( )
inline

Generates a random unsigned integer between zero and std::numeric_limits<u8>::max() - 1

◆ genFP() [1/2]

template<class T >
YAKL_INLINE T yakl::Random::genFP ( )
inline

Generates a random floating point value between 0 and 1

Parameters
TThe type of the floating point number

◆ genFP() [2/2]

template<class T >
YAKL_INLINE T yakl::Random::genFP ( lb,
ub 
)
inline

Generates a random floating point value between lb and ub

Parameters
TThe type of the floating point number
lbLower bound of the random number
ubUpper bound of the random number

◆ operator=() [1/2]

YAKL_INLINE Random& yakl::Random::operator= ( Random &&  in)
inline

Moves a Random object.

◆ operator=() [2/2]

YAKL_INLINE Random& yakl::Random::operator= ( Random const &  in)
inline

Copies a Random object.

◆ set_seed()

YAKL_INLINE void yakl::Random::set_seed ( u8  seed)
inline

Assigns a seed. Warm-up of 20 iterations.


The documentation for this class was generated from the following file: