Random number between negative and positive value - Javascript Data Type

Javascript examples for Data Type:Number

Description

Random number between negative and positive value

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  av  a  2s.c om*/
function getNonZeroRandomNumber(){
    var random = Math.floor(Math.random()*199) - 99;
    if(random==0) 
       return getNonZeroRandomNumber();
    return random;
}
for(i=0;i<100;i++)
    console.log(getNonZeroRandomNumber()+", ");

    });

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

Related Tutorials