Add a PRNG
This commit is contained in:
parent
5f2a2cdc05
commit
11d1fbec34
1 changed files with 10 additions and 0 deletions
10
lib/prng.ts
Normal file
10
lib/prng.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
export type Prng = () => number;
|
||||||
|
|
||||||
|
export function mulberry32(state: number) {
|
||||||
|
return function () {
|
||||||
|
let t = (state += 0x6d2b79f5);
|
||||||
|
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||||
|
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||||
|
return (t ^ (t >>> 14)) >>> 0;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue