Remove "framework"
This commit is contained in:
parent
b45bdb18a0
commit
dc86d30eb2
72 changed files with 359 additions and 333 deletions
20
src/helper/random.ts
Normal file
20
src/helper/random.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { polyfillImul } from './polyfill-imul';
|
||||
|
||||
export class Random {
|
||||
public constructor(private seed: number) {
|
||||
polyfillImul();
|
||||
}
|
||||
|
||||
public get next(): number {
|
||||
// result is in [0, 1)
|
||||
return ((2 ** 31 - 1) & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31;
|
||||
}
|
||||
|
||||
public choose<T>(list: Array<T>): T {
|
||||
return list[Math.floor(this.randomInInterval(0, list.length))];
|
||||
}
|
||||
|
||||
public randomInInterval(aClosed: number, bOpen: number): number {
|
||||
return (bOpen - aClosed) * this.next + aClosed;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue