title: JavaScript Math.random() returns "Undefined"
body: <p>I have a block of code that uses Math.random(). I noticed that occasionally the return value would be "Undefined". This is the code I used: </p>
  
  <pre><code>return data.map(val =&gt; {
      var r = Math.random();
      if (r &lt; this.mutChance) {
          console.log(Math.random);
          debugger;
          return this.rDna(val);
      }
      return val;
  });
  </code></pre>
  
  <p>When i set the mutChance variable to 0 and let the code run for a bit eventually debugger gets called and shows the value of r to be undefined. I tried to reproduce the problem by running in console</p>
  
  <pre><code>var test = Math.random();
  while(test){
      test = Math.random();
  }
  </code></pre>
  
  <p>However, this loop never ended. I have no idea why the function would act differently within my object, and the console.log(Math.random); Says that the function still has its native code. Nowhere do I override the random function, nor do I use the variable r anywhere else.</p>
  
  <p>I am relatively new to JavaScript and couldn't find this problem anywhere else. The only other code I have imported is the p5.min.js package.</p>