Updates:
Summary: Want more random bits in Math.random()
Labels: Type-FeatureRequest Priority-Low
Comment #1 on issue 3127 by [email protected]: Want more random bits
in Math.random()
http://code.google.com/p/v8/issues/detail?id=3127
It's not a bias. V8's RNG only has 32 bits of randomness. Your shifting
those right by 33 bits, then you're adding another fractional part (X *
(2^33 + 1) == x*2^33 + x), so the number you're flooring always has the
following bit pattern:
[32 random bits] 0 . [32 random bits]
Which obviously makes Math.floor() return an even result.
Multiply with a slightly smaller number and you'll observe proper
randomness in the last bit:
Array.apply(null, Array(10000)).reduce(function(a){ return a +
(Math.floor(Math.random() * (Math.pow(2,32) + 1)) % 2)}, 0)
4991
Array.apply(null, Array(10000)).reduce(function(a){ return a +
(Math.floor(Math.random() * (Math.pow(2,32) + 1)) % 2)}, 0)
5045
Array.apply(null, Array(10000)).reduce(function(a){ return a +
(Math.floor(Math.random() * (Math.pow(2,32) + 1)) % 2)}, 0)
5035
Array.apply(null, Array(10000)).reduce(function(a){ return a +
(Math.floor(Math.random() * (Math.pow(2,32) + 1)) % 2)}, 0)
4966
I'm not sure how important it is to increase the "precision" (number of
bits) of the RNG.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.