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

seeded random numbers? #109

Open
ianstormtaylor opened this issue Jun 2, 2022 · 0 comments
Open

seeded random numbers? #109

ianstormtaylor opened this issue Jun 2, 2022 · 0 comments

Comments

@ianstormtaylor
Copy link

I love the Random helpers in this library, but I'm looking to use them for generative art, and I need a way to create seeded random numbers for consitent, repeatable outputs.

I was wondering if you'd be open to having an extra optional argument added to the functions. For example:

// from...
function bernoulli(p = 0.5) {}

// to...
function bernoulli(p = 0.5, random = Math.random) {}

So for example in p5.js you could do:

let r = Random.bernoulli(0.5, p.random)

Alternatively, the existing random helpers could be refactored to be a class that can be instantiated as well as used as static methods. So you could do:

let random = new Random(p.random)
let r = random.bernoulli()

Which might be nicer.

This would also make it easy to use libraries like seedrandom or seed-random too.

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

No branches or pull requests

1 participant