Skip to content
modkitv0.2

rand.h

#include <modkit/rand.h>12 functions · 1 structs · 1 typedefs

Seedable pseudo-random number generator (PCG32).

A small, fast, deterministic RNG. Use an explicit mk_rng for reproducible streams (procedural generation, replays, tests), or the global convenience functions for quick one-offs (raylib GetRandomValue style).

Functions

mk_random_floatfunction

float mk_random_float(void)

Global float in [0,1).

Returns The resulting value.

mk_random_intfunction

int mk_random_int(int lo, int hi)

Global integer in [lo,hi] inclusive.

ParameterTypeDescription
lointValue for lo.
hiintValue for hi.

Returns The resulting value.

mk_random_rangefunction

float mk_random_range(float lo, float hi)

Global float in [lo,hi).

ParameterTypeDescription
lofloatValue for lo.
hifloatValue for hi.

Returns The resulting value.

mk_random_seedfunction

void mk_random_seed(uint64_t seed)

Seed the global RNG used by mk_random_*.

ParameterTypeDescription
seeduint64_tValue for seed.

mk_rng_boolfunction

bool mk_rng_bool(mk_rng *r)

Boolean coin flip.

ParameterTypeDescription
rmk_rng *Value for r.

Returns True when the operation succeeds.

mk_rng_floatfunction

float mk_rng_float(mk_rng *r)

Float in [0,1).

ParameterTypeDescription
rmk_rng *Value for r.

Returns The resulting value.

mk_rng_in_spherefunction

mk_vec3 mk_rng_in_sphere(mk_rng *r)

Uniform point inside the unit sphere.

ParameterTypeDescription
rmk_rng *Value for r.

Returns The resulting value.

mk_rng_intfunction

int mk_rng_int(mk_rng *r, int lo, int hi)

Integer in [lo,hi] inclusive (lo<=hi).

ParameterTypeDescription
rmk_rng *Value for r.
lointValue for lo.
hiintValue for hi.

Returns The resulting value.

mk_rng_on_spherefunction

mk_vec3 mk_rng_on_sphere(mk_rng *r)

Uniform point on the unit sphere surface.

ParameterTypeDescription
rmk_rng *Value for r.

Returns The resulting value.

mk_rng_rangefunction

float mk_rng_range(mk_rng *r, float lo, float hi)

Float in [lo,hi).

ParameterTypeDescription
rmk_rng *Value for r.
lofloatValue for lo.
hifloatValue for hi.

Returns The resulting value.

mk_rng_seedfunction

void mk_rng_seed(mk_rng *r, uint64_t seed)

Seed an RNG.

ParameterTypeDescription
rmk_rng *Value for r.
seeduint64_tValue for seed.

mk_rng_u32function

uint32_t mk_rng_u32(mk_rng *r)

Next 32-bit value.

ParameterTypeDescription
rmk_rng *Value for r.

Returns The resulting value.

Structs

mk_rngstruct

PCG32 state.

Treat as opaque; seed with mk_rng_seed before use.

FieldTypeDescription
stateuint64_tThe state.
incuint64_tThe inc.

Typedefs

mk_rngtypedef

typedef struct mk_rng mk_rng

PCG32 state.

Treat as opaque; seed with mk_rng_seed before use.