#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);
}
