Generate random number between 2 variables - Javascript Math

Javascript examples for Math:random

Description

Generate random number between 2 variables

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w  w w .  j a  v a  2s.  com
var minNumber = -100;
var maxNumber = 40
var randomNumber = randomNumberFromRange(minNumber, maxNumber);
function randomNumberFromRange(min,max)
{
    return Math.floor(Math.random()*(max-min+1)+min);
}
console.log(randomNumber);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials