Refactor
This commit is contained in:
parent
de7fcc15d0
commit
9e582110ea
27 changed files with 248 additions and 123 deletions
20
src/utils/random.ts
Normal file
20
src/utils/random.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue