MathUtils.seededRandom() returned value is linearly correlated to the parameter
See original GitHub issueHey,
According to the doc, MathUtils.seededRandom() should return a (pseudo random) float in the interval [0, 1]. However the returned value is linearly correlated to the provided integer parameter: the bigger the seed, the bigger the result.
For instance:
MathUtils.seededRandom(1); // returns 0.000007825903601782307
MathUtils.seededRandom(10); // returns 0.00007826322696941274
MathUtils.seededRandom(100); // returns 0.0007826364606457171
MathUtils.seededRandom(1000); // returns 0.00782636879740876
As far as I know, the results of a prng function shouldn’t be so predictable, but maybe I’m misunderstanding something.
Three.js version: 0.138.0
Cheers
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Seeding the random number generator in Javascript
I have written a function that returns a seeded random number, it uses Math.sin to have a long random ...
Read more >A more complete random API? - 💡 Ideas - TC39 - Discourse
Right now, in Javascript, our main source of randomness comes from a single function: Math.random(). I'm wondering if there would be interest in...
Read more >Stan Modeling Language
This allows adjustment for globally scaled or correlated parameters. Without this adjustment, models with differently scaled parameters ...
Read more >Math.random() - JavaScript - MDN Web Docs
The Math.random() function returns a floating-point, pseudo-random number that's ... This example returns a random number between the specified values.
Read more >Stan User's Guide
Stan supports regression models from simple linear regressions to ... where I() is the indicator function taking the value 1 if its argument...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, let’s give this a try then 👍 .
Well the current behavior just doesn’t work as it should. So I’m not sure the current seededRandom function could be used in a scenario where a PRNG is needed.
That’s true. In that case you could always rewrite the MathUtils.seededRandom function with the mulberry32 algorithm this way:
The behavior would then be fixed: