title: How to test with Math.random in JavaScript?
body: <p>I have a function that will select a random value between a min and a max value. So when I have a test where I test that the value fall between the min and max value. But as there where some failures in my app the test passed some times and some times fails due to the randomness.</p>
  
  <p>Would it be a good idea to override/mock <code>Math.random()</code> to return 0 and 1 and test that my value is same as max or min value? Or are there better ways to test randomness in JavaScript?</p>
  
  <p>Here is the function that will be used to create the random number: </p>
  
  <pre><code>function constrain(min, max){
      return Math.round(Math.random() * (max - min) + min)
  }
  </code></pre>