94#define BJ_RAND_MAX 0x7FFF
211 const uint32_t high = (uint32_t)
bj_rand();
212 const uint32_t mid = (uint32_t)
bj_rand();
213 const uint32_t low = (uint32_t)
bj_rand();
214 return (high << 17) | (mid << 2) | (low >> 13);
327#if defined(BJ_API_LONG_DOUBLE)
328 #define bj_random_uniform bj_random_uniform_ld
329#elif defined(BJ_API_FLOAT64)
330 #define bj_random_uniform bj_random_uniform_f64
332 #define bj_random_uniform bj_random_uniform_f32
366 float standard_deviation
384 double standard_deviation
402 long double standard_deviation
414#if defined(BJ_API_LONG_DOUBLE)
415 #define bj_random_normal bj_random_normal_ld
416#elif defined(BJ_API_FLOAT64)
417 #define bj_random_normal bj_random_normal_f64
419 #define bj_random_normal bj_random_normal_f32
494#if defined(BJ_API_LONG_DOUBLE)
495 #define bj_random_normal_range bj_random_normal_range_ld
496#elif defined(BJ_API_FLOAT64)
497 #define bj_random_normal_range bj_random_normal_range_f64
499 #define bj_random_normal_range bj_random_normal_range_f32
506 int32_t low, int32_t high);
509 uint32_t low, uint32_t high);
512 float low,
float high);
515 double low,
double high);
518 long double low,
long double high);
523 float mean,
float standard_deviation);
526 double mean,
double standard_deviation);
529 long double mean,
long double standard_deviation);
532 float min,
float max);
535 double min,
double max);
538 long double min,
long double max);
541#define bj_uniform_real_distribution bj_random_uniform
543#define bj_normal_real_distribution bj_random_normal
545#define bj_normal_real_minmax_distribution bj_random_normal_range
General-purpose definitions for Banjo API.
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
float bj_real
Selected real type for float configuration.
uint64_t inc
Stream selector; odd recommended, 0 allowed.
uint64_t state
Current internal state (updated each step).
void bj_seed_pcg32(struct bj_pcg32 *generator, uint64_t seed, uint64_t seq)
Set the generator state from seed and sequence.
int bj_random_bernoulli(bj_random_u32_fn next, void *state, bj_real probability)
Bernoulli(probability).
long double bj_random_normal_ld(bj_random_u32_fn next, void *state, long double mean, long double standard_deviation)
Normal long double N(mean, standard_deviation^2).
long double bj_random_uniform_ld(bj_random_u32_fn next, void *state, long double low, long double high)
Uniform long double in [low, high).
uint32_t bj_pcg32_min(void)
Smallest possible value returned by the generator.
uint32_t bj_min_pcg32(void)
uint32_t bj_uniform_uint32_distribution(bj_random_u32_fn next, void *state, uint32_t low, uint32_t high)
long double bj_normal_long_double_minmax_distribution(bj_random_u32_fn next, void *state, long double min, long double max)
double bj_normal_double_distribution(bj_random_u32_fn next, void *state, double mean, double standard_deviation)
double bj_normal_double_minmax_distribution(bj_random_u32_fn next, void *state, double min, double max)
static uint32_t bj_pcg32_generator(void *state)
Adapter for distribution API (void* state).
float bj_normal_float_minmax_distribution(bj_random_u32_fn next, void *state, float min, float max)
int32_t bj_uniform_int32_distribution(bj_random_u32_fn next, void *state, int32_t low, int32_t high)
long double bj_uniform_long_double_distribution(bj_random_u32_fn next, void *state, long double low, long double high)
int32_t bj_random_uniform_i32(bj_random_u32_fn next, void *state, int32_t low, int32_t high)
Uniform signed 32-bit integer in [low, high].
double bj_random_uniform_f64(bj_random_u32_fn next, void *state, double low, double high)
Uniform double in [low, high).
int bj_bernoulli_distribution(bj_random_u32_fn next, void *state, bj_real probability)
long double bj_random_normal_range_ld(bj_random_u32_fn next, void *state, long double min, long double max)
Normal long double from a min/max pair (μ ≈ (min+max)/2, σ ≈ (max-min)/6).
float bj_random_normal_range_f32(bj_random_u32_fn next, void *state, float min, float max)
Normal float from a min/max pair (μ ≈ (min+max)/2, σ ≈ (max-min)/6).
void bj_discard_pcg32(struct bj_pcg32 *generator, uint64_t z)
Advance the generator state by z steps.
float bj_normal_float_distribution(bj_random_u32_fn next, void *state, float mean, float standard_deviation)
static uint32_t bj_rand_generator(void *state)
Adapter exposing the global bj_rand engine to the distribution API.
double bj_random_normal_range_f64(bj_random_u32_fn next, void *state, double min, double max)
Normal double from a min/max pair (μ ≈ (min+max)/2, σ ≈ (max-min)/6).
float bj_uniform_float_distribution(bj_random_u32_fn next, void *state, float low, float high)
uint32_t bj_random_uniform_u32(bj_random_u32_fn next, void *state, uint32_t low, uint32_t high)
Uniform unsigned 32-bit integer in [low, high].
uint32_t bj_max_pcg32(void)
float bj_random_normal_f32(bj_random_u32_fn next, void *state, float mean, float standard_deviation)
Normal float N(mean, standard_deviation^2).
long double bj_normal_long_double_distribution(bj_random_u32_fn next, void *state, long double mean, long double standard_deviation)
void bj_srand(unsigned int seed)
Seed the standard PRNG.
double bj_uniform_double_distribution(bj_random_u32_fn next, void *state, double low, double high)
uint32_t bj_pcg32_max(void)
Largest possible value returned by the generator.
double bj_random_normal_f64(bj_random_u32_fn next, void *state, double mean, double standard_deviation)
Normal double N(mean, standard_deviation^2).
int bj_rand(void)
Generate a pseudo-random integer in [0, BJ_RAND_MAX].
uint32_t bj_next_pcg32(struct bj_pcg32 *generator)
Advance the generator and return the next 32-bit value.
uint32_t(* bj_random_u32_fn)(void *state)
RNG callback type for generator-agnostic distributions.
float bj_random_uniform_f32(bj_random_u32_fn next, void *state, float low, float high)
Uniform float in [low, high).
C99 math shim with bj_real precision type and scalar utilities.