package sim // Rng_State is owned by Sim_State so all gameplay randomness is seed-driven and // replayable. No gameplay code should use global/random platform state directly. Rng_State :: struct { value: u64, } // Initialize the deterministic random stream from the run seed. A zero seed is // remapped so the generator always has a useful non-zero state to advance from. rng_from_seed :: proc(seed: u64) -> Rng_State { state := seed if state == 0 { state = 0x9E3779B97F4A7C15 } return Rng_State{value = state} } // Advance and return the next deterministic random value. SplitMix64 is small, // fast, and stable enough for this substrate; if later gameplay needs separate // random domains, those should become explicit named streams in Sim_State. rng_next_u64 :: proc(rng: ^Rng_State) -> u64 { rng.value += 0x9E3779B97F4A7C15 z := rng.value z = (z ~ (z >> 30)) * 0xBF58476D1CE4E5B9 z = (z ~ (z >> 27)) * 0x94D049BB133111EB return z ~ (z >> 31) }