Skip to content
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

Alternative API #16

Open
mfbx9da4 opened this issue Sep 5, 2021 · 1 comment
Open

Alternative API #16

mfbx9da4 opened this issue Sep 5, 2021 · 1 comment

Comments

@mfbx9da4
Copy link

mfbx9da4 commented Sep 5, 2021

I think it would be nice to overload Math.random

function random(): number
function random(opts: EmptyObject): number
function random(opts: { seed: number }): RandomNumberGenerator

interface RandomNumberGenerator {
  next: () => number
  fork: () => RandomNumberGenerator 
}

type EmptyObject = Record<string, never>
@mfbx9da4
Copy link
Author

mfbx9da4 commented Sep 5, 2021

Also note fork here will create a new RNG which is predictably forked from the current one. ie does something like


fork = () => random({ seed: this.next() })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant