cxsrandlib
Functions
cxsrandlib.h File Reference

This library implements a seeded xorshift pseudorandom number generator. More...

Include dependency graph for cxsrandlib.h:

Go to the source code of this file.

Functions

uint32_t cxsrandlib_u32 (uint32_t *state)
 Return a seeded pseudorandom unsigned 32 bit integer. More...
 
int32_t cxsrandlib_i32_range (int32_t lo, int32_t bound, uint32_t xorbits, uint32_t *state)
 Return a seeded pseudorandom signed 32 bit integer in the range [lo, bound). More...
 
uint32_t cxsrandlib_u32_range (uint32_t lo, uint32_t bound, uint32_t xorbits, uint32_t *state)
 Return a seeded pseudorandom unsigned 32 bit integer in the range [lo, bound). More...
 
double cxsrandlib_double (uint32_t *state)
 Return a seeded pseudorandom double in the range [0, 1]. More...
 
void cxsrandlib_normal2 (double mean, double stddev, double out[2], uint32_t *state)
 Output two seeded pseudorandom doubles according to the normal distribution specified by mean and stddev using the Marsaglia polar method. More...
 
double cxsrandlib_normal (double mean, double stddev, uint32_t *state)
 Return a seeded pseudorandom double according to the normal distribution specified by mean and stddev using the Marsaglia polar method. More...
 

Detailed Description

This library implements a seeded xorshift pseudorandom number generator.

Function Documentation

◆ cxsrandlib_u32()

uint32_t cxsrandlib_u32 ( uint32_t *  state)

Return a seeded pseudorandom unsigned 32 bit integer.

Parameters
[in,out]stateSeeded state (must be initialized non-zero)

◆ cxsrandlib_i32_range()

int32_t cxsrandlib_i32_range ( int32_t  lo,
int32_t  bound,
uint32_t  xorbits,
uint32_t *  state 
)

Return a seeded pseudorandom signed 32 bit integer in the range [lo, bound).

Results returned are uniform except with regard to modulo bias. If bound is less than or equal to lo, lo is returned and state is unmodified.

Parameters
[in]loInclusive lower bound
[in]boundExclusive upper bound
[in]xorbitsTransform result before bounds adjustment is applied
[in,out]stateSeeded state (must be initialized non-zero)

◆ cxsrandlib_u32_range()

uint32_t cxsrandlib_u32_range ( uint32_t  lo,
uint32_t  bound,
uint32_t  xorbits,
uint32_t *  state 
)

Return a seeded pseudorandom unsigned 32 bit integer in the range [lo, bound).

Results returned are uniform except with regard to modulo bias. If bound is less than or equal to lo, lo is returned and state is unmodified.

Parameters
[in]loInclusive lower bound
[in]boundExclusive upper bound
[in]xorbitsTransform result before bounds adjustment is applied
[in,out]stateSeeded state (must be initialized non-zero)

◆ cxsrandlib_double()

double cxsrandlib_double ( uint32_t *  state)

Return a seeded pseudorandom double in the range [0, 1].

Parameters
[in,out]stateSeeded state (must be initialized non-zero)

◆ cxsrandlib_normal2()

void cxsrandlib_normal2 ( double  mean,
double  stddev,
double  out[2],
uint32_t *  state 
)

Output two seeded pseudorandom doubles according to the normal distribution specified by mean and stddev using the Marsaglia polar method.

This function has a cycle limited fallback to prevent theoretical infinite recursion.

Parameters
[in]meanMean of the normal distribution
[in]stddevStandard deviation of the normal distribution
[out]outArray in which to output two doubles
[in,out]stateSeeded state (must be initialized non-zero)

◆ cxsrandlib_normal()

double cxsrandlib_normal ( double  mean,
double  stddev,
uint32_t *  state 
)

Return a seeded pseudorandom double according to the normal distribution specified by mean and stddev using the Marsaglia polar method.

This function operates by calling cxsrandlib_normal2 and discarding one of the outputs.

Parameters
[in]meanMean of the normal distribution
[in]stddevStandard deviation of the normal distribution
[in,out]stateSeeded state (must be initialized non-zero)