Will repeating Math.random?

For various JavaScript implementations Math.random:

Putting aside problems with memory and length, will it ultimately have an ever-repeating sequence of numbers (for example, it depends only on the internal seed, and when this seed completes to the starting point, will the numbers repeat)?

sequence = Math.random();
while(true){
    sequence += ', ' + Math.random();
}

Will each client have the same repeating sequence (for example, clients do not include client-specific data in the random number generation process)?


I ask because if a possible sequence of numbers is a limited subset, things like generating UUIDs with Math.random will have a much greater chance of collision.

+4
5

MDN:

. Math.random() . -, . API Web Crypto, window.crypto.getRandomValues ​​().

, .

+5

mdn Math.random() , , .

, window.crypto.getRandomValues(), , , .

; reset .

. Math.random() . -, . Crypto API, window.crypto.getRandomValues ​​().

+2

, , . , ... . , Java: Dig this SO question .

" ", " ", .

:

V8 Windows s_rand , . /dev/urandom , . urandom , unix, . , V8 . Java , , , FireFox, .

Firefox - , , Java. , V8, s_rand /dev/urandom, , , .

, "", (Chrome Firefox ), , , . , , , , .

, .

:

+2

; , , . Javascripts Math.Random() . , , , , Math.random() - .

http://bocoup.com/weblog/random-numbers/ .

0

No, while nothing in the calculations is truly random, the algorithms that are used to create these “random” numbers make it random, so you will never get a repeating pattern. Most (I'm not sure about Math.random) randomization functions will get the current timestamp and use it as part of this process, and this is one of the main reasons why you will not get duplicate data in this case.

-1
source

All Articles