This commit is contained in:
Andras Schmelczer 2023-04-29 11:58:14 +01:00
commit 9e582110ea
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
27 changed files with 248 additions and 123 deletions

20
src/utils/random.ts Normal file
View file

@ -0,0 +1,20 @@
export abstract class Random {
// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript, Mulberry32
private static _seed = 42;
public static set seed(value: number) {
Random._seed = value;
}
public static getRandom(): number {
let t = (Random._seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
public static randomBetween(from: number, to: number): number {
return from + Random.getRandom() * (to - from);
}
}