JavaScript Random

1/22/2020 4:45:16 AM

In the JavaScript have random function this function basically generate the random number. This function has pre define so we just use our purpose. We can over load the function like input the max-number or min-number. This function under “Math” property. If we cannot pass the parameter just use the random function, we get the default output between 0 to 1. Also, we pass the parameter of the random function and get our expected output. In the ‘Math’ object have ‘floor’ function, this function responsible to   round the number figure. Now given bellow the random function code and explain the code:

<!DOCTYPE html>
<script type="text/javascript">
   // Use random function
   //declear two vareabole and assign
   var maxValue=25;
   var minValue=20;
   var result=Math.random();
   console.log("Defolt values of the random function: "+result);
   //Now i want to print random number 20-25
var expResult=Math.floor(Math.random() * (maxValue-minValue+1))+minValue;
console.log("Our expeted out put: "+expResult);

In the code we will show the JavaScript in random method. This method generates the random number. Also, floor method responsible to round figure the float number.