Generate random numbes in a range : random « Math « JavaScript Tutorial






<html>
<head>
<title>die Roller</title>
<script>
var rollRaw = 0;
var rollBigger = 0;
var rollInt = 0;
var rollFinal = 0;
var result = "";

rollRaw = Math.random();
rollBigger = rollRaw * 6;
rollInt = Math.floor(rollBigger);
rollFinal = rollInt + 1;

result = "rollRaw: " + rollRaw + "\n";
result += "rollBigger: " + rollBigger + "\n";
result += "rollInt: " + rollInt + "\n";
result += "rollFinal: " + rollFinal + "\n";

alert(result);

</script>
</head>
<body>
</body>
</html>








9.21.random
9.21.1.Math.random()
9.21.2.Use Math.random to generate random number
9.21.3.Math.round a random number
9.21.4.Generate a random integer between 2 and 10
9.21.5.Generate random URL
9.21.6.Generate random numbes in a range