libhatchet
Loading...
Searching...
No Matches
hxrandom Class Reference

#include <hxrandom.hpp>

Public Member Functions

constexpr hxrandom (uint64_t stream_=1u)
constexpr uint32_t operator() (void)
template<typename T>
constexpr T range (T base_, T size_)
constexpr double range (double base_, double size_)
constexpr int64_t range (int64_t base_, int64_t size_)
constexpr uint64_t range (uint64_t base_, uint64_t size_)
void read (void *bytes_, hxsize_t count_)
constexpr uint8_t u8 (void)
constexpr uint16_t u16 (void)
constexpr uint32_t u32 (void)
constexpr uint64_t u64 (void)
constexpr float f01 (void)
constexpr double d01 (void)

Detailed Description

hxrandom - 64-bit MMIX LCG.

Knuth, D. 2002. (Modified to perturb the return value so that all bits are of equal quality.) Uses a floating point multiply instead of integer modulo when generating numbers in a range. Requires at least 64-bit integer emulation as well. Has a period of 2^64 and passes routine numerical tests with only eight bytes of state while using simple arithmetic. Intended for test data or games, not mathematical applications.

Constructor & Destructor Documentation

◆ hxrandom()

hxrandom::hxrandom ( uint64_t stream_ = 1u)
inlineconstexpr

Constructor to initialize the random number generator.

  • stream : Index or seed value for a given stream of random numbers.

Member Function Documentation

◆ d01()

double hxrandom::d01 ( void )
inlineconstexpr

Returns a double between [0..1).

Can safely be used to generate array indices without overflowing.

◆ f01()

float hxrandom::f01 ( void )
inlineconstexpr

Returns a float between [0..1).

Can safely be used to generate array indices without overflowing.

◆ operator()()

uint32_t hxrandom::operator() ( void )
inlineconstexpr

Returns [0..2^32).

◆ range() [1/4]

double hxrandom::range ( double base_,
double size_ )
inlineconstexpr

double version.

◆ range() [2/4]

int64_t hxrandom::range ( int64_t base_,
int64_t size_ )
inlineconstexpr

int64_t version. Negative or zero size is undefined.

◆ range() [3/4]

template<typename T>
T hxrandom::range ( T base_,
T size_ )
inlineconstexpr

Returns a random number in the range [base..base+range).

range(0.0f,10.0f) returns 0.0f to 9.999f and not 10.0f. Uses a floating point multiply instead of a divide. base + size must not overflow the type and size must be positive.

  • base : The beginning of the range. e.g., 0.
  • size : Positive size of the range. e.g., 10 elements.

◆ range() [4/4]

uint64_t hxrandom::range ( uint64_t base_,
uint64_t size_ )
inlineconstexpr

uint64_t version. Zero size is undefined.

◆ read()

void hxrandom::read ( void * bytes_,
hxsize_t count_ )
inline

Reads a specified number of random bytes into the provided buffer.

uint32_t generated using u32. Use hxsizeof for a signed count.

  • bytes : Non-null pointer to a buffer large enough for count bytes.
  • count : Number of bytes to read.

◆ u16()

uint16_t hxrandom::u16 ( void )
inlineconstexpr

Returns [0..2^16).

◆ u32()

uint32_t hxrandom::u32 ( void )
inlineconstexpr

Returns [0..2^32).

◆ u64()

uint64_t hxrandom::u64 ( void )
inlineconstexpr

Returns [0..2^64).

◆ u8()

uint8_t hxrandom::u8 ( void )
inlineconstexpr

Returns [0..2^8).


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