Javascript Random


Javascript Random Numbers :-

Math.random() method returns value between zero and  one, you must normalize its return value to fit the range of numbers required of your application. An easy way to get random integers in the range m to n is as follows:

Math.round(Math.random() * (n-m) +m;

So , to simulate a die roll you would use.

Roll = Math.round ( Math.random() * (7-2)) + 2;


Number :-

Number is the built in object corresponding to the primitive number data type.

Var         a = new    Number();

Var         b  = new   Number(19.5);

toString() , which returns the value of the number in a string. Generally a number type converts to a string when we need to use it as such.

Javascript Random

Follow Us

Contact Us

Back to Top