CGVIS Utils
Loading...
Searching...
No Matches
Random Class Reference

#include <Rand.h>

Public Member Functions

 Random ()
 Construct and seed from std::random_device.
 Random (uint32_t seed)
 Construct with a deterministic seed.
float rand005 ()
 Draw a random float in [0, 0.5).
float rand051 ()
 Draw a random float in [0.5, 1).
float rand01 ()
 Draw a random float in [0, 1).
float rand11 ()
 Draw a random float in [-1, 1).
float rand0Pi ()
 Draw a random float in [0, $\pi$).
template<typename T>
T rand (T a, T b)
 Draw a value uniformly in the half-open interval [a, b).
template<typename T>
void shuffle (std::vector< T > &a)
 Shuffle a container in-place using Fisher–Yates.

Constructor & Destructor Documentation

◆ Random() [1/2]

Random::Random ( )

Construct and seed from std::random_device.

◆ Random() [2/2]

Random::Random ( uint32_t seed)

Construct with a deterministic seed.

Parameters
seedSeed value for the underlying PRNG.

Member Function Documentation

◆ rand()

template<typename T>
T Random::rand ( T a,
T b )
inline

Draw a value uniformly in the half-open interval [a, b).

Template Parameters
TArithmetic type (typically float/double/int). For integral types, the result is produced by scaling a [0,1) float and casting.
Parameters
aLower bound (inclusive).
bUpper bound (exclusive conceptually; for integers, distribution is effectively over the discrete set starting at a).
Returns
A value in the range [a, b).
Warning
For integral T the mapping is via cast from float and thus not perfectly uniform over the integers.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rand005()

float Random::rand005 ( )

Draw a random float in [0, 0.5).

Returns
Value $ x \in [0,0.5) $.

◆ rand01()

float Random::rand01 ( )

Draw a random float in [0, 1).

Returns
Value $ x \in [0,1) $.
Here is the caller graph for this function:

◆ rand051()

float Random::rand051 ( )

Draw a random float in [0.5, 1).

Returns
Value $ x \in [0.5,1) $.

◆ rand0Pi()

float Random::rand0Pi ( )

Draw a random float in [0, $\pi$).

Returns
Value $ x \in [0,\pi) $ (radians).

◆ rand11()

float Random::rand11 ( )

Draw a random float in [-1, 1).

Returns
Value $ x \in [-1,1) $.

◆ shuffle()

template<typename T>
void Random::shuffle ( std::vector< T > & a)
inline

Shuffle a container in-place using Fisher–Yates.

Template Parameters
TElement type contained in the vector.
Parameters
aContainer to shuffle.
Note
Uses this instance's PRNG via rand<size_t>().
Here is the call graph for this function:

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