pxl8/client/src/core/pxl8_rng.c
asrael 49256db1bd refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG
- asset/: ase loader, cart, save, embed
- gfx/: graphics, animation, atlas, fonts, tilemap, transitions
- sfx/: audio
- script/: lua/fennel runtime, REPL
- hal/: platform abstraction (SDL3)
- world/: BSP, world, procedural gen
- math/: math utilities
- game/: GUI, replay
- lua/: Lua API modules
2026-01-15 08:41:59 -06:00

24 lines
585 B
C

#include "pxl8_rng.h"
void pxl8_rng_seed(pxl8_rng* rng, u32 seed) {
if (!rng) return;
rng->state = seed ? seed : 1;
}
u32 pxl8_rng_next(pxl8_rng* rng) {
if (!rng) return 0;
rng->state ^= rng->state << 13;
rng->state ^= rng->state >> 17;
rng->state ^= rng->state << 5;
return rng->state;
}
f32 pxl8_rng_f32(pxl8_rng* rng) {
return (f32)pxl8_rng_next(rng) / (f32)0xFFFFFFFF;
}
i32 pxl8_rng_range(pxl8_rng* rng, i32 min, i32 max) {
if (min >= max) return min;
u32 range = (u32)(max - min);
return min + (i32)(pxl8_rng_next(rng) % range);
}