Is the following a pure function?
function test(min,max) {
return Math.random() * (max - min) + min;
}
My understanding is that a pure func
In addition to the other answers that correctly point out how this function is non-deterministic, it also has a side-effect: it will cause future calls to math.random()
to return a different answer. And a random-number generator that doesn’t have that property will generally perform some kind of I/O, such as to read from a random device provided by the OS. Either is verboten for a pure function.