-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from Pseudo-Corp/seeded-rng-2
seeded rng
- Loading branch information
Showing
8 changed files
with
66 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MersenneTwister } from 'fast-mersenne-twister' | ||
import { player } from './Synergism' | ||
|
||
export const seededRandom = (index: SeedValues) => MersenneTwister(player.seed[index]++).random() | ||
|
||
/** | ||
* Generates a random number (inclusive) between {@param min} and {@param max}. | ||
* @param min min | ||
* @param max max | ||
*/ | ||
export const seededBetween = (index: SeedValues, min: number, max: number) => | ||
Math.floor(seededRandom(index) * (max - min + 1) + min) | ||
|
||
export const Seed = { | ||
PromoCodes: 0, | ||
Ambrosia: 1 | ||
} as const | ||
|
||
export type SeedValues = typeof Seed[keyof typeof Seed] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
declare module 'fast-mersenne-twister' { | ||
interface api { | ||
genrand_int32: () => number | ||
// [0,0x7fffffff] | ||
genrand_int31: () => number | ||
// [0,1] | ||
genrand_real1: () => number | ||
// [0,1) | ||
genrand_real2: () => number | ||
// (0,1) | ||
genrand_real3: () => number | ||
// [0,1), 53-bit resolution | ||
genrand_res53: () => number | ||
|
||
randomNumber: () => number | ||
random31Bit: () => number | ||
randomInclusive: () => number | ||
random: () => number // returns values just like Math.random | ||
randomExclusive: () => number | ||
random53Bit: () => number | ||
} | ||
|
||
export function MersenneTwister (seed?: number): api | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters