davidbau / seedrandom

seeded random number generator for Javascript
2.04k stars 160 forks source link

A string of characters that are all the same used as a seed, no matter the length, results in the same output. #48

Closed ChildishGiant closed 6 years ago

ChildishGiant commented 7 years ago
Math.seedrandom("a")
Math.random() -> 0.43449421599986604
Math.seedrandom("aa")
Math.random() -> 0.43449421599986604
Math.seedrandom("aaaaaaa")
Math.random() -> 0.43449421599986604
davidbau commented 6 years ago

From the readme:

The standard ARC4 key scheduler cycles short keys, which means that seedrandom('ab') is equivalent to seedrandom('abab') and 'ababab'. Therefore it is a good idea to add a terminator to avoid trivial equivalences on short string seeds, e.g., Math.seedrandom(str + '\0'). Starting with version 2.0, a terminator is added automatically for non-string seeds, so seeding with the number 111 is the same as seeding with '111\0'.

In the interest of compatibility, we are staying with this scheme.

ChildishGiant commented 6 years ago

Okay, thanks for the explanation 😄