Javascript examples for Math:random
Generate a random integer from range
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w . j av a 2s . c o m*/ var range = "13-50".split("-") var minlen = parseInt(range[0]); var maxlen = parseInt(range[1]); if (!isNaN(minlen) && !isNaN(maxlen)) { //Pick a number from range length = Math.floor(Math.random() * (maxlen - minlen + 1)) + minlen; console.log(length); } } </script> </head> <body> </body> </html>