SOURCE / PINNED RELEASE
Made of little things.
Sickman Survival
- Release
- 7335c9fdf0a8…
- Author-recorded commit
- cbd2eeafa70d…
- License
- LICENSE
- Author’s source reference
- nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.napplet.soy%2F/n-8804151df7f
Archive hash verified: 591bab4addcbe5fc…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
/** Small seeded PRNG (mulberry32) so a world can be regenerated from its seed. */
export interface Rng {
next(): number;
range(min: number, max: number): number;
int(min: number, max: number): number;
chance(p: number): boolean;
sign(): 1 | -1;
}
export function createRng(seed: number): Rng {
let a = seed >>> 0;
const next = (): number => {
a = (a + 0x6d2b79f5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
return {
next,
range: (min, max) => min + next() * (max - min),
int: (min, max) => Math.floor(min + next() * (max - min + 1)),
chance: (p) => next() < p,
sign: () => (next() < 0.5 ? -1 : 1),
};
}
