-
Notifications
You must be signed in to change notification settings - Fork 11
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
Better randomization, especially for GUID generation #99
Comments
I agree that |
Do you think Mersenne Twister would do the trick? I used that once to get repeatable random numbers (you can set the seed). Perhaps it will work for your purposes too. |
The page I referenced mentions Mersenne Twister a couple times and precludes using it since it fails Crush randomness tests. |
I was thinking about it and I fell that providing a single algorithm is not going to be a good idea and is also out of the scope of this project (besides the fact that it is really hard to test PRNG properly). I think we should add a way to swap the PRNG used by each method so you could curry each method individually and use different seeds for each one: var mt = new MersenneTwister('magic beans seed');
var mtRandom = function(){ return mt.random() };
var randInt_1 = randInt.create( mtRandom );
var randInt_2 = randInt.create( KISS07('sunflower seed') ); And also add a way to replace it on an existing instance: // default value = Math.random;
randInt.random = Kybos('foobar'); And maybe create a new module define(function(){
function random(){
return random.random();
}
// expose a `random` property so user can swap the behavior dynamically
random.random = Math.random;
return random;
}); Could also use the RequireJS map config to replace the PS: that way we also avoid any licensing issues. |
I definitely like the flexibility that having a separate module, Having said that |
I added the I didn't implemented the I improved the documentation a lot adding info on the top about Thanks for all the feedback and for helping me to improve amd-utils. Feel free to reopen the issue. |
for future reference this article is great: http://www.empiricalzeal.com/2012/12/21/what-does-randomness-look-like/ |
Thanks! I'll check it out. |
In general you should not depend on
Math.random()
for anything related to GUID generation. This page explains the issue in detail as well provides JavaScript algorithms that provide better randomization. Consider adopting one those, likely Kybos since it is clearly licensed.The text was updated successfully, but these errors were encountered: