davidbau / seedrandom

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

Strings consisting of a repeated pattern cause collisions #63

Closed nbuonin closed 5 years ago

nbuonin commented 5 years ago

I've found that using strings that consist of repeating patterns cause the number generator to return identical results.

For example, suppose that you seed seedrandom with a string 'sfsf'. Then seed it again with 'sfsfsf'. Both number generators will produce 0.12427751372875664 on the first call.

In Node.js:

let rngA = seedrandom('sf');
let a = rngA();

let rngB = seedrandom('sfsf');
let b = rngB();

assert(a !== b);

It doesn't seem to matter how many times the pattern repeats. I could use 'sfsfsf' or 'sfsfsfsfsfsf' and get the same result.

I would expect these to be totally different values because they are different strings.

flyingmutant commented 5 years ago

This is "working as expected": https://github.com/davidbau/seedrandom/issues/48#issuecomment-331904087

nbuonin commented 5 years ago

Got it, I just needed to RTFM: https://github.com/davidbau/seedrandom#version-notes