Math.random随机位数 [英] Math.random number of random bits
问题描述
是否要求生成多少随机位 Math.random
?我对Chrome和Firefox的实现进行了一些测试,将结果转换为十六进制以检查位,Firefox 27.0.1给出了结果,如
Is there any requirement on how many random bits Math.random
is supposed to produce? I did some tests on Chrome and Firefox's implementations, converting the results to hex to examine the bits, and Firefox 27.0.1 gives results like
0x1.de619579d56f3p-1
0x1.ef1ada9306decp-2
0x1.df3b75e208ce6p-1
而Chrome版本33.0.1750.154 m给出
whereas Chrome Version 33.0.1750.154 m gives
0x1.1190f39c00000p-2
0x1.b959e3b600000p-1
0x1.90f614b400000p-2
相比较神奇。它似乎是一个32位的结果,而Firefox的值似乎使用了53个随机位。
which is godawful in comparison. It appears to be a 32-bit result, whereas Firefox's values seem to use 53 random bits.
推荐答案
http://www.ecma-international.org/ecma-262/5.1/# sec-15.8.2.14
15.8.2.14 random()
15.8.2.14 random ( )
使用依赖于实现的算法或策略,返回具有正号,大于或等于0但小于1的Number值,随机或伪随机选择,在该范围内具有近似均匀的分布。这个函数没有参数。
Returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments.
似乎是所有的规范说的。
Seems to be all the spec says.
这篇关于Math.random随机位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!