davidbau / seedrandom

seeded random number generator for Javascript
2.06k stars 160 forks source link

Allow undefined to be passed as an argument to randomly seed #2

Closed tremby closed 10 years ago

tremby commented 11 years ago

Instead of being able to do

Math.seedrandom(specialCase ? specialSeed : undefined);

where I might want it to be randomly seeded, but in a special case I want a particular seed, I currently need to write

if (specialCase) Math.seedrandom(specialSeed);
else Math.seedrandom()

I had expected undefined to work the same way as no argument at all, but it is being converted to a string undefined\0. Maybe null should work the same way too.

The second code sample isn't much more complicated, I concede, but the first is more concise and I fully expected it to work.

davidbau commented 10 years ago

I agree; null and undefined should work the same as omitting the argument.

I'll soon look at releasing a version 2.3 based on this: http://davidbau.com/encode/seedrandom-test.js

The idea will be to (1) fix the two reported issues; and (2) also not crash when autoseeding within the node.js environment.

Let me know if you notice any issues with the draft new version above.

davidbau commented 10 years ago

Fixed in version 2.3. You can pass null as the first argument to autoseed.