Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math.random number of random bits

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

whereas Chrome Version 33.0.1750.154 m gives

0x1.1190f39c00000p-2
0x1.b959e3b600000p-1
0x1.90f614b400000p-2

which is godawful in comparison. It appears to be a 32-bit result, whereas Firefox's values seem to use 53 random bits.

like image 535
user2357112 supports Monica Avatar asked Mar 23 '14 11:03

user2357112 supports Monica


1 Answers

http://www.ecma-international.org/ecma-262/5.1/#sec-15.8.2.14

15.8.2.14 random ( )

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.

like image 65
Håkan Lindqvist Avatar answered Oct 19 '22 19:10

Håkan Lindqvist