|
void | bj_srand (unsigned int seed) |
int | bj_rand (void) |
void | bj_seed_pcg32 (bj_pcg32 *generator, uint64_t seed, uint64_t seq) |
uint32_t | bj_next_pcg32 (bj_pcg32 *generator) |
void | bj_discard_pcg32 (bj_pcg32 *generator, uint64_t z) |
uint32_t | bj_min_pcg32 (void) |
uint32_t | bj_max_pcg32 (void) |
static uint32_t | bj_pcg32_generator (void *state) |
int32_t | bj_uniform_int32_distribution (bj_random_u32_fn_t next, void *state, int32_t low, int32_t high) |
float | bj_uniform_float_distribution (bj_random_u32_fn_t next, void *state, float low, float high) |
double | bj_uniform_double_distribution (bj_random_u32_fn_t next, void *state, double low, double high) |
long double | bj_uniform_long_double_distribution (bj_random_u32_fn_t next, void *state, long double low, long double high) |
int | bj_bernoulli_distribution (bj_random_u32_fn_t next, void *state, bj_real probability) |
float | bj_normal_float_distribution (bj_random_u32_fn_t next, void *state, float mean, float standard_deviation) |
double | bj_normal_double_distribution (bj_random_u32_fn_t next, void *state, double mean, double standard_deviation) |
long double | bj_normal_long_double_distribution (bj_random_u32_fn_t next, void *state, long double mean, long double standard_deviation) |
Random number generation utilities.
◆ bj_pcg32_t
Data Fields |
uint64_t |
inc |
Stream selector; odd recommended, 0 allowed. |
uint64_t |
state |
Current internal state (updated each step). |
◆ bj_normal_real_distribution
Alias to the real-typed normal distribution for the active precision.
Maps to:
- bj_normal_long_double_distribution if BJ_API_LONG_DOUBLE
- bj_normal_double_distribution if BJ_API_FLOAT64
- bj_normal_float_distribution otherwise
◆ BJ_RAND_MAX
#define BJ_RAND_MAX 0x7FFF |
Maximum value returned by bj_rand().
Matches the stdlib idea of RAND_MAX. Values from bj_rand() are distributed in [0, BJ_RAND_MAX].
◆ bj_uniform_real_distribution
Alias to the real-typed uniform distribution for the active precision.
Maps to:
- bj_uniform_long_double_distribution if BJ_API_LONG_DOUBLE
- bj_uniform_double_distribution if BJ_API_FLOAT64
- bj_uniform_float_distribution otherwise
◆ bj_pcg32
◆ bj_random_u32_fn_t
typedef uint32_t(* bj_random_u32_fn_t) (void *state) |
RNG callback type for generator-agnostic distributions.
- Parameters
-
state | Opaque engine state pointer. |
- Returns
- Next 32-bit pseudo-random value.
◆ bj_bernoulli_distribution()
Bernoulli(probability).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
probability | Probability in [0,1]. |
- Returns
- 1 with the given probability, else 0.
◆ bj_discard_pcg32()
void bj_discard_pcg32 |
( |
bj_pcg32 * | generator, |
|
|
uint64_t | z ) |
Advance the generator state by z steps.
- Parameters
-
generator | Generator pointer (must not be NULL). |
z | Number of steps to skip ahead. |
◆ bj_max_pcg32()
uint32_t bj_max_pcg32 |
( |
void | | ) |
|
Largest possible value returned by the generator.
- Returns
- Always 0xFFFFFFFF.
◆ bj_min_pcg32()
uint32_t bj_min_pcg32 |
( |
void | | ) |
|
Smallest possible value returned by the generator.
- Returns
- Always 0.
◆ bj_next_pcg32()
uint32_t bj_next_pcg32 |
( |
bj_pcg32 * | generator | ) |
|
Advance the generator and return the next 32-bit value.
- Parameters
-
generator | Generator pointer (must not be NULL). |
- Returns
- Next 32-bit pseudo-random value.
◆ bj_normal_double_distribution()
double bj_normal_double_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
double | mean, |
|
|
double | standard_deviation ) |
Normal double N(mean, standard_deviation^2).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
mean | Mean. |
standard_deviation | Standard deviation (>= 0). |
- Returns
- double sample.
◆ bj_normal_float_distribution()
float bj_normal_float_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
float | mean, |
|
|
float | standard_deviation ) |
Normal float N(mean, standard_deviation^2).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
mean | Mean. |
standard_deviation | Standard deviation (>= 0). |
- Returns
- float sample.
◆ bj_normal_long_double_distribution()
long double bj_normal_long_double_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
long double | mean, |
|
|
long double | standard_deviation ) |
Normal long double N(mean, standard_deviation^2).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
mean | Mean. |
standard_deviation | Standard deviation (>= 0). |
- Returns
- long double sample.
◆ bj_pcg32_generator()
uint32_t bj_pcg32_generator |
( |
void * | state | ) |
|
|
inlinestatic |
Adapter for distribution API (void* state).
Allows bj_pcg32 to be used with callbacks of type uint32_t (*)(void* state).
- Parameters
-
- Returns
- Next 32-bit pseudo-random value.
◆ bj_rand()
Generate a pseudo-random integer in [0, BJ_RAND_MAX].
Linear congruential generator (LCG) using: X_{n+1} = (1103515245 * X_n + 12345) mod 2^31
Returns the high-order bits truncated to BJ_RAND_MAX range.
- Returns
- Integer in [0, BJ_RAND_MAX].
◆ bj_seed_pcg32()
void bj_seed_pcg32 |
( |
bj_pcg32 * | generator, |
|
|
uint64_t | seed, |
|
|
uint64_t | seq ) |
Set the generator state from seed and sequence.
- Parameters
-
generator | Generator pointer (must not be NULL). |
seed | Initial seed value. |
seq | Stream selector (LSB forced to 1 internally). |
◆ bj_srand()
void bj_srand |
( |
unsigned int | seed | ) |
|
Seed the standard PRNG.
- Parameters
-
seed | Seed value. Same seed reproduces the same sequence. |
◆ bj_uniform_double_distribution()
double bj_uniform_double_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
double | low, |
|
|
double | high ) |
Uniform double in [low, high).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
low | Inclusive lower bound. |
high | Exclusive upper bound. |
- Returns
- double in [low, high).
◆ bj_uniform_float_distribution()
float bj_uniform_float_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
float | low, |
|
|
float | high ) |
Uniform float in [low, high).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
low | Inclusive lower bound. |
high | Exclusive upper bound. |
- Returns
- float in [low, high).
◆ bj_uniform_int32_distribution()
int32_t bj_uniform_int32_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
int32_t | low, |
|
|
int32_t | high ) |
Uniform 32-bit integer in [low, high].
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
low | Inclusive lower bound. |
high | Inclusive upper bound. |
- Returns
- int32 in [low, high].
◆ bj_uniform_long_double_distribution()
long double bj_uniform_long_double_distribution |
( |
bj_random_u32_fn_t | next, |
|
|
void * | state, |
|
|
long double | low, |
|
|
long double | high ) |
Uniform long double in [low, high).
- Parameters
-
next | RNG callback (e.g., bj_pcg32_generator). |
state | Opaque engine state for next. |
low | Inclusive lower bound. |
high | Exclusive upper bound. |
- Returns
- long double in [low, high).