-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid seek leaking by crating local prng #4
Comments
https://www.npmjs.com/package/seedrandom to keep api consistent we could create our own global random generator seeded with eg. Date.now(). This will prevent polluting Math.random() but will still cause leaks between Nodes. To fix that we could provide constructor e.g. import { randomFloat, create } from `pex-random`
const rndLocalNoSeed = create()
const rndLocalSeed = create("randomstring")
//0..1 using "global" random generator
randomFloat()
//0..1 using "local" random generator using global seed
rndLocalSeed.randomFloat()
//0..1 using "local" random generator using local seed
rndLocalSeed.randomFloat() The difference between those to would be that if other pieces of your app code / nodes use global random generator they can reset it by calling global randomSeed() and having local generator prevents that. Not providing a seed in create() would "inherit" current seed from global generator but then diverge from it independently after use. Other local generators that also use initial global seed would start from the same point and could produce same sequence on numbers. To avoid that we could use Date.now() or global seed + some global counter tracking how many custom random generators have been created. |
var myrng = new Math.seedrandom('hello.');
The text was updated successfully, but these errors were encountered: