bn::random class
#include <bn_random.h>

Fast, deterministic random number generator.

Its current implementation is a Marsaglia's xorshf generator.

See https://github.com/raylee/xorshf96/blob/master/xorshf96.c

Public functions

auto get() -> unsigned constexpr
Returns a random unsigned integer greater or equal than 0, updating its internal seed in the process.
auto get_int() -> int constexpr
Returns a random signed integer greater or equal than 0, updating its internal seed in the process.
auto get_fixed() -> fixed constexpr
Returns a random bn::fixed greater or equal than 0, updating its internal seed in the process.
auto get_int(int limit) -> int constexpr
Returns a random signed integer in the range [0..limit), updating its internal seed in the process.
auto get_fixed(fixed limit) -> fixed constexpr
Returns a random bn::fixed in the range [0..limit), updating its internal seed in the process.
auto get_int(int minimum, int limit) -> int constexpr
Returns a random signed integer in the range [minimum..limit), updating its internal seed in the process.
auto get_fixed(fixed minimum, fixed limit) -> fixed constexpr
Returns a random bn::fixed in the range [minimum..limit), updating its internal seed in the process.
auto get_unbiased_int(int limit) -> int constexpr
Returns a random signed integer in the range [0..limit), updating its internal seed in the process.
auto get_unbiased_fixed(fixed limit) -> fixed constexpr
Returns a random bn::fixed in the range [0..limit), updating its internal seed in the process.
auto get_unbiased_int(int minimum, int limit) -> int constexpr
Returns a random signed integer in the range [minimum..limit), updating its internal seed in the process.
auto get_unbiased_fixed(fixed minimum, fixed limit) -> fixed constexpr
Returns a random bn::fixed in the range [minimum..limit), updating its internal seed in the process.
void update() constexpr
Updates the value of the internal seed.

Function documentation

int bn::random::get_int(int limit) constexpr

Returns a random signed integer in the range [0..limit), updating its internal seed in the process.

Parameters
limit Returned value is lower than this value.
Returns Random signed integer in the range [0..limit).

It's possible that the output will be biased towards smaller numbers due to modulo bias.

random::get_unbiased_int can be used to avoid modulo bias.

fixed bn::random::get_fixed(fixed limit) constexpr

Returns a random bn::fixed in the range [0..limit), updating its internal seed in the process.

Parameters
limit Returned value is lower than this value.
Returns Random bn::fixed in the range [0..limit).

It's possible that the output will be biased towards smaller numbers due to modulo bias.

random::get_unbiased_fixed can be used to avoid modulo bias.

int bn::random::get_int(int minimum, int limit) constexpr

Returns a random signed integer in the range [minimum..limit), updating its internal seed in the process.

Parameters
minimum Returned value is greater or equal than this value.
limit Returned value is lower than this value.
Returns Random signed integer in the range [minimum..limit).

It's possible that the output will be biased towards smaller numbers due to modulo bias.

random::get_unbiased_int can be used to avoid modulo bias.

fixed bn::random::get_fixed(fixed minimum, fixed limit) constexpr

Returns a random bn::fixed in the range [minimum..limit), updating its internal seed in the process.

Parameters
minimum Returned value is greater or equal than this value.
limit Returned value is lower than this value.
Returns Random bn::fixed in the range [minimum..limit).

It's possible that the output will be biased towards smaller numbers due to modulo bias.

random::get_unbiased_fixed can be used to avoid modulo bias.

int bn::random::get_unbiased_int(int limit) constexpr

Returns a random signed integer in the range [0..limit), updating its internal seed in the process.

Parameters
limit Returned value is lower than this value.
Returns Random signed integer in the range [0..limit).

This implementation avoids modulo bias, so it's less likely that the output will be biased towards smaller numbers.

fixed bn::random::get_unbiased_fixed(fixed limit) constexpr

Returns a random bn::fixed in the range [0..limit), updating its internal seed in the process.

Parameters
limit Returned value is lower than this value.
Returns Random bn::fixed in the range [0..limit).

This implementation avoids modulo bias, so it's less likely that the output will be biased towards smaller numbers.

int bn::random::get_unbiased_int(int minimum, int limit) constexpr

Returns a random signed integer in the range [minimum..limit), updating its internal seed in the process.

Parameters
minimum Returned value is greater or equal than this value.
limit Returned value is lower than this value.
Returns Random signed integer in the range [minimum..limit).

This implementation avoids modulo bias, so it's less likely that the output will be biased towards smaller numbers.

fixed bn::random::get_unbiased_fixed(fixed minimum, fixed limit) constexpr

Returns a random bn::fixed in the range [minimum..limit), updating its internal seed in the process.

Parameters
minimum Returned value is greater or equal than this value.
limit Returned value is lower than this value.
Returns Random bn::fixed in the range [minimum..limit).

This implementation avoids modulo bias, so it's less likely that the output will be biased towards smaller numbers.