davidbau / seedrandom

seeded random number generator for Javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

inverted Math.round() result

AtzepengPK opened this issue · comments

Idk if it really is an issue but i dont understand this behavior:

var rng = seedrandom('hello');
let i = rng.quick()

var rng2 = seedrandom('hello1');
let i2 = rng2.quick()

console.log(i);
console.log(Math.round(i));
console.log(Math.round(rng.quick()));

console.log(i2);
console.log(Math.round(i2));
console.log(Math.round(rng2.quick()));

results in :

0.5463663768023252
1
0
0.4120498853735626
0
1

same behavior with rng().
anyone can explain this to me?
using v 3.0.5

Thanks

@AtzepengPK what's wrong with that, please? Or what's not clear?

Maybe this will explain the mystery to @AtzepengPK. Each time you call rng.quick() you get the next value. The first two values of the hello and hello1 sequence happen to be bigger then less than 0.5, and less than and bigger than 0.5, respectively.

Running in node:

> sr = require('./seedrandom')
[Function: seedrandom]
> q = sr('hello')
{ [Function: prng] int32: [Function], quick: [Function], double: [Circular] }
> q.quick()
0.5463663768023252
> q.quick()
0.0504581592977047
> q = sr('hello1')
{ [Function: prng] int32: [Function], quick: [Function], double: [Circular] }
> q.quick()
0.4120498853735626
> q.quick()
0.6297062321100384