Refactor
This commit is contained in:
parent
41d4665e49
commit
969ccac690
24 changed files with 236 additions and 287 deletions
17
src/framework/helper/random.ts
Normal file
17
src/framework/helper/random.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
export class Random {
|
||||
public constructor(private seed: number) {}
|
||||
|
||||
public get next(): number {
|
||||
return (
|
||||
((2 ** 31 - 1) & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31
|
||||
);
|
||||
}
|
||||
|
||||
public choose<T>(list: Array<T>): T {
|
||||
return list[this.randomInInterval(0, list.length)];
|
||||
}
|
||||
|
||||
public randomInInterval(aClosed: number, bOpen: number): number {
|
||||
return Math.floor((bOpen - aClosed) * this.next) + aClosed;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue