In an ideal world, Math.random () will be completely random, and one output will be completely independent of the other, which (provided that p = the probability of any given number) leads to the probability p ^ 2 for any value is repeated immediately after the other (as already others said).
In practice, people want Math.random to be fast, which means that pseudo random number generators are used by engines. There are many different types of PRNG, but the simplest is a linear congruent generator, which is basically a line-by-line function:
s(n + 1) = some_prime * s(n) + some_value mod some_other_prime
If such a generator is used, you will not see the value repeating until you name random() some_other_prime times. You are guaranteed by this.
More recently, however, it has become apparent that this behavior (combined with sowing PRNG with the current time) can be used to track some forms, which has led browsers to do a number of things, meaning that you cannot accept anything from subsequent calls random() .
olliej
source share