dimanche 22 mars 2015

How to generate random number in a range through java script?

I am using the code mentioned below to generate random numbers. The problem is that I want to control the random numbers between 140-142 (like 141.65,142.12,143.56,142.15 and so on), the Math.Random is strictly random and is not getting restricted to the range. Can anybody suggest me the right code for this. I am not able to understand the right way to do it. It is for my website.


<html xmlns="http://ift.tt/lH0Osb" > <head> <title>Random Number in JavaScript</title> <script type="text/javascript"> var randomNumber = Math.floor(Math.random() * 15) + 146; document.write("<p>" + randomNumber + "</p>");

</script> </head> <body><meta http-equiv="refresh" content="2;URL=">


enter code here </html>





Aucun commentaire:

Enregistrer un commentaire