Quantcast
Channel: Is a function that calls Math.random() pure? - Stack Overflow
Browsing all 10 articles
Browse latest View live

Answer by Joshua for Is a function that calls Math.random() pure?

Would you be fine with the following:return (""+ test(0,1)) + test(0,1);be equivalent tovar temp = test(0, 1);return (""+ temp) + temp;?You see, the definition of pure is a function whose output does...

View Article



Answer by Adam Kotwasinski for Is a function that calls Math.random() pure?

From mathematical point of view, your signature is nottest: <number, number> -> <number>buttest: <environment, number, number> -> <environment, number>where the...

View Article

Answer by Davislor for Is a function that calls Math.random() pure?

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....

View Article

Answer by senderle for Is a function that calls Math.random() pure?

The simple answer to your question is that Math.random() violates rule #2.Many other answers here have pointed out that the presence of Math.random() means that this function is not pure. But I think...

View Article

Answer by Shubhnik Singh for Is a function that calls Math.random() pure?

No, it isn't a pure function because its output doesn't depend only on the input provided (Math.random() can output any value), while pure functions should always output the same value for same...

View Article


Answer by Héctor for Is a function that calls Math.random() pure?

No, it isn't. You can't figure out the result at all, so this piece of code can't be tested. To make that code testable, you need to extract the component that generates the random number: function...

View Article

Answer by Rishabh Mishra for Is a function that calls Math.random() pure?

Pure functions always return the same value for same input.Pure functions are predictable and are referential transparent which means that we can replace the function call with the output returned and...

View Article

Answer by TKoL for Is a function that calls Math.random() pure?

A pure function is a function where the return value is only determined by its input values, without observable side effectsBy using Math.random, you are determining its value by something other than...

View Article


Answer by Christian Benseler for Is a function that calls Math.random() pure?

No, it's not. Given the same input, this function will return different values. And then you can't build a 'table' that maps the input and the outputs.From the Wikipedia article for Pure function: The...

View Article


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

Is the following a pure function?function test(min,max) { return Math.random() * (max - min) + min;}My understanding is that a pure function follows these conditions:It returns a value computed from...

View Article
Browsing all 10 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>