Generate a random integer between 2 and 10 : random : Math JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Math » random »

 

Generate a random integer between 2 and 10

















<html>
<head>
<title>Example</title>
</head>
<body>
<script type="text/javascript">
function selectFrom(startValue, endValue) {
    var iChoices = endValue - startValue + 1;
    return Math.floor(Math.random() * iChoices + startValue);
}


var iNum = selectFrom(210);

alert(iNum);
</script>

</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Math
» random