Is a function that calls Math.random() pure?

后端 未结 9 1698
[愿得一人]
[愿得一人] 2021-01-30 15:30

Is the following a pure function?

function test(min,max) {
   return  Math.random() * (max - min) + min;
}

My understanding is that a pure func

9条回答
  •  無奈伤痛
    2021-01-30 15:53

    A pure function is a function where the return value is only determined by its input values, without observable side effects

    By using Math.random, you are determining its value by something other than input values. It's not a pure function.

    source

提交回复
热议问题