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

What is window.generativeMusic.rng() ? #8

Open
tatecarson opened this issue Feb 13, 2021 · 2 comments
Open

What is window.generativeMusic.rng() ? #8

tatecarson opened this issue Feb 13, 2021 · 2 comments

Comments

@tatecarson
Copy link

HI Alex,

I'm exploring the code trying to learn how you made some of these and I'm running into an issue. You have this window.generativeMusic.rng() in use all over the place but I can not find where it is defined. Is it some sort of random seed?

Thanks.

@alexbainter
Copy link
Contributor

Hi again Tate!

The implementation is a little hacky but it's just a random number generator that defaults to Math.random.

https://github.com/generative-music/pieces-alex-bainter/blob/1186f13dc24a42e5485cc39ede313328f64b4b61/packages/utilities/src/wrap-activate.js#L8-L9

I wanted to add a reward for people who supported Generative.fm where I'd use their name to seed the random number generator, but I'd already written so much code where I just used the global Math.random(). So I just replaced those with window.generativeMusic.rng(), and then I could override it with a another (seedable) rng. For example, here's where I do that in Generative.fm Play: https://github.com/generative-fm/play/blob/11ae5750c0c1aac2ba7b2be5626ebca8c687d434/src/app/redux-app.jsx#L32-L35

@alexbainter
Copy link
Contributor

I'll be sure to note this in the readme

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

2 participants