random icon indicating copy to clipboard operation
random copied to clipboard

Predictable pseudo random number

Open yanickrochon opened this issue 6 years ago • 4 comments

I expected this module to return the same sequence of random numbers if seeded with the same value. But it seems completely unpredictable. I'm I missing something?

const rng = random.clone(seed).uniform();

rng();
rng();
rng();

I would've expected the three rnd() calls to return the same random numbers every time.

yanickrochon avatar Feb 24 '19 05:02 yanickrochon

This was definitely a bug; sorry about that.

I just published a fix that hopefully resolves your issue as v2.1.1.

transitive-bullshit avatar Feb 24 '19 15:02 transitive-bullshit

Thank you, but unfortunately it does not. The same example provided in this issue always returns different values, even giving the same seed.

yanickrochon avatar Feb 24 '19 20:02 yanickrochon

@transitive-bullshit Will this be resolved?

frankiesimon avatar Aug 06 '19 15:08 frankiesimon

Same issue here.

Fortunatly this problem seems to be solved when using seedrandom explicitly:

// always random
const rng = random.clone('my-new-seed')
 
// always the same results
const rng2 = random.clone(seedrandom('kittyfoo'))

pieterdb4477 avatar Jan 09 '20 07:01 pieterdb4477

Just tested with v4 and this has been resolved after this fix https://github.com/transitive-bullshit/random/commit/4243d10c8139fe18878f4b186ad18ff67cac789c

transitive-bullshit avatar Nov 08 '22 08:11 transitive-bullshit