I expect that every time I call the function it will pass 1 as the value of seed parameter and so that value = 1 * 16807 in returned function so the result of every call will be 16807 I don't understand how this function work
function pseudoRandom(seed) {
let value = seed;
return function() {
value = value * 16807;
return value;
}
}
let generator = pseudoRandom(1);
alert(generator()); // 16807
alert(generator()); // 282475249
alert(generator()); // 1622650073
value = value * 16807;
<-- no longer seedgenerator()
the previous value ofvalue
is used, not ofseed
.1622650073
you need to use the prescribed algorithm:value = value * 16807 % 2147483647
.