Javascript examples for Math:random
The random() method returns a random number from 0 up to but not including 1.
None
A Number, representing a number from 0 up to but not including 1
The following code shows how to return a random number between a range:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w . j a v a2 s .c o m var x = document.getElementById("demo") x.innerHTML = Math.floor((Math.random() * 100) + 1); } </script> </body> </html>