tc39 / proposal-seeded-random

Proposal for an options argument to be added to JS's Math.random() function, and some options to start it with.
MIT License
156 stars 6 forks source link

Allow control over range/distribution? #6

Closed tabatkins closed 5 years ago

tabatkins commented 6 years ago

Per @jfbastien, C++ touched somewhat, but ineffectively, on letting the user control the range/distribution of random numbers. Lack of good specification means that, while the ordinary generator is consistent between impls, the alternate distributions are not. Should we allow specifying this?

Like #5, I think this is a valuable addition, but is equally valuable for Math.random(). (The number of times I've written a randInt() function for myself, or faked a uniform() by averaging three Math.random() calls...) Like #5, I'd like to defer this to a separate proposal for upgrading both random functions, unless the committee decides they'd like to broaden this to altering Math.random() too.

jfbastien commented 6 years ago

Reference for C++

Note how distribution (such as uniform int) don't specify much. See the libc++ implementation.

Compare:

Note that re-running each compiler gives you the same result, always, but because they have a different STL implementation they don't agree on results because they compute distribution differently.

bakkot commented 6 years ago

I'm on board with adding more distributions, but don't think this proposal is the place to do it. The concern with reproducibility across engines is important, but I think that's satisfied by precisely specifying the algorithm used.

tabatkins commented 5 years ago

Yeah, I'm gonna go ahead and close this. If we want to add multiple algos & control over distribution, that's a great thing to discuss for a v2; for v1 just matching Math.random()'s distribution is good and simple (and settling on one prng algo).