How is randomness achieved with Math.random in javascript?

From the specifications:

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.

So the answer is that it depends on what JavaScript engine you’re using.

I’m not sure if all browsers use the same strategy or what that strategy is unfortunately

It should be fine for your purposes. Only if you’re doing a large amount of numbers would you begin to see a pattern

Leave a Comment