Abstraction for a source of random or pseudorandom bits.
More...
#include <geomc/random/Random.h>
|
| Random (void) |
| Construct a new random number generator with an implementation-selected seed.
|
|
| Random (uint64_t seed) |
|
virtual uint32_t | rand32 ()=0 |
|
virtual void | rseed (uint64_t seed)=0 |
| Reset the generator's state with the bits of seed as its source of entropy. More...
|
|
template<typename T > |
T | rand () |
|
template<typename T > |
T | rand (T max) |
|
template<typename T > |
T | rand (T lo, T hi) |
|
template<> |
bool | rand () |
|
template<> |
unsigned int | rand () |
|
template<> |
int | rand () |
|
template<> |
unsigned long | rand () |
|
template<> |
long | rand () |
|
template<> |
unsigned long long | rand () |
|
template<> |
long long | rand () |
|
template<> |
float | rand () |
|
template<> |
double | rand () |
|
template<> |
unsigned int | rand (unsigned int hi) |
|
template<> |
int | rand (int hi) |
|
template<> |
unsigned long | rand (unsigned long hi) |
|
template<> |
long | rand (long hi) |
|
template<> |
unsigned long long | rand (unsigned long long hi) |
|
template<> |
long long | rand (long long hi) |
|
template<> |
float | rand (float hi) |
|
template<> |
double | rand (double hi) |
|
template<> |
int | rand (int lo, int hi) |
|
template<> |
long long | rand (long long lo, long long hi) |
|
template<> |
float | rand (float lo, float hi) |
|
template<> |
double | rand (double lo, double hi) |
|
template<> |
bool | rand () |
|
template<> |
unsigned int | rand () |
|
template<> |
int | rand () |
|
template<> |
unsigned long | rand () |
|
template<> |
long | rand () |
|
template<> |
unsigned long long | rand () |
|
template<> |
long long | rand () |
|
template<> |
float | rand () |
|
template<> |
double | rand () |
|
template<> |
unsigned int | rand (unsigned int hi) |
|
template<> |
int | rand (int hi) |
|
template<> |
unsigned long | rand (unsigned long hi) |
|
template<> |
long | rand (long hi) |
|
template<> |
unsigned long long | rand (unsigned long long hi) |
|
template<> |
long long | rand (long long hi) |
|
template<> |
float | rand (float hi) |
|
template<> |
double | rand (double hi) |
|
template<> |
int | rand (int lo, int hi) |
|
template<> |
long long | rand (long long lo, long long hi) |
|
template<> |
float | rand (float lo, float hi) |
|
template<> |
double | rand (double lo, double hi) |
|
|
uint32_t | _bitpool |
|
unsigned int | _bitsleft |
|
Abstraction for a source of random or pseudorandom bits.
Implementations provide random bits by overriding rand32()
, which should return no fewer than 32 random bits.
Client-friendly random numbers are exposed via Random::rand<T>()
. Specializations are provided for a selection of primitive T
. Specializations of rand()
for other T
may be written, which will automatically be inherited by all subclasses of Random
.
The general contract of rand()
which should be followed by all specializations:
rand(void)
- If
T
is discrete, than this function should return values evenly over the entire space of possible T
.
- If
T
is a continuous type, then this function should return values evenly over an analogue of the interval [0,1], inclusive.
rand(T max)
- Should return random values evenly distributed over all possible states between 0 (or the
T
analogue of 0) and the value of max
rand(T lo, T hi)
- Should return random values evenly distributed over all possible states bounded by
lo
and hi
◆ Random()
Construct a new random number generator with the bits of seed
as a source of entropy.
◆ rand() [1/24]
Produces a (pseudo-) random T
with uniform distribution over the unit interval, if the unit interval is populated by T
; or with uniform distribution over the entire space of possible T
otherwise.
For example, rand<float>()
returns a random float between 0 and 1.0, while rand<unsigned int>()
returns a random uint
between 0 and UINT_MAX
.
◆ rand() [2/24]
- Returns
- A random boolean value.
◆ rand() [3/24]
- Returns
- An
unsigned int
between 0 and UINT_MAX
.
◆ rand() [4/24]
- Returns
- An
int
between INT_MIN
and INT_MAX
.
◆ rand() [5/24]
- Returns
- An
unsigned long
between 0 and ULONG_MAX
.
◆ rand() [6/24]
- Returns
- A
long
between LONG_MIN
and LONG_MAX
.
◆ rand() [7/24]
unsigned long long rand |
( |
| ) |
|
- Returns
- An
unsigned long long
betwen 0 and ULLONG_MAX
.
◆ rand() [8/24]
- Returns
- A
long long
between LLONG_MIN
and LLONG_MAX
.
◆ rand() [9/24]
Generate a floating-point value with uniform distribution between 0 and 1.0.
This method is preferable to use over the common practice of rand<int>() / (float)INT_MAX
, as the latter excludes a large fraction of the representable floating point numbers between 0.0 and 1.0 (particularly those near zero), resulting in reduced entropy.
This method produces a number by carefully picking the bits of the exponent and mantissa explicitly, in such a way that the distibution remains uniform.
◆ rand() [10/24]
Generate a floating-point value with uniform distribution between 0 and 1.0.
This method is preferable to use over the common practice of rand<int>() / (float)INT_MAX
, as the latter excludes a large fraction of the representable floating point numbers between 0.0 and 1.0 (particularly those near zero), resulting in reduced entropy.
This method produces a number by carefully picking the bits of the exponent and mantissa explicitly, in such a way that the distibution remains uniform.
◆ rand() [11/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
double
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [12/24]
double rand |
( |
double |
lo, |
|
|
double |
hi |
|
) |
| |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- An
double
between lo
and hi
.
◆ rand() [13/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
float
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [14/24]
float rand |
( |
float |
lo, |
|
|
float |
hi |
|
) |
| |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- An
float
between lo
and hi
.
◆ rand() [15/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A number between 0 and
hi
(regardless of the sign of hi
).
◆ rand() [16/24]
int rand |
( |
int |
lo, |
|
|
int |
hi |
|
) |
| |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- An
int
between lo
and hi
.
◆ rand() [17/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
long
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [18/24]
long long rand |
( |
long long |
hi | ) |
|
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
long long
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [19/24]
long long rand |
( |
long long |
lo, |
|
|
long long |
hi |
|
) |
| |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- A
long long
between lo
and hi
.
◆ rand() [20/24]
Produces a (pseudo-) random T
with uniform distribution between lo
and hi
.
- Parameters
-
lo | Lower bound for possible T samples. |
hi | Upper bound for possible T samples. |
◆ rand() [21/24]
Produces a (pseudo-) random T
with uniform distribution between the T
analogue of 0
and max
.
- Parameters
-
max | Upper bound of possible T samples. |
◆ rand() [22/24]
unsigned int rand |
( |
unsigned int |
hi | ) |
|
- Parameters
-
hi | Upper bound of random number. |
- Returns
- An
unsigned int
between 0 and hi
.
◆ rand() [23/24]
unsigned long rand |
( |
unsigned long |
hi | ) |
|
- Parameters
-
hi | Upper bound of random number. |
- Returns
- An
unsigned long
between 0 and hi
.
◆ rand() [24/24]
unsigned long long rand |
( |
unsigned long long |
hi | ) |
|
- Parameters
-
hi | Upper bound of random number. |
- Returns
- An
unsigned long long
between 0 and hi
.
◆ rand32()
virtual uint32_t rand32 |
( |
| ) |
|
|
pure virtual |
◆ rseed()
virtual void rseed |
( |
uint64_t |
seed | ) |
|
|
pure virtual |
Reset the generator's state with the bits of seed
as its source of entropy.
Implemented in LCRand, MTRand, and XoshiroRand.
The documentation for this class was generated from the following files: