Professional Documents
Culture Documents
RANDOM NUMBERS
PROF. DAVID ROSSITER
1/13
2/13
WE WILL LOOK AT
Math.random()
Math.floor()
3/13
OVERVIEW
Generate a random number
Set up the range
Throw away the decimal place
4/13
5/13
6/13
<!doctypehtml>
<html>
<body>
<script>
varrandom_number
random_number=Math.random()
alert(random_number)
</script>
</body>
</html>
7/13
8/13
9/13
<!doctypehtml>
<html>
<body>
<script>
varrandom_number
random_number=Math.random()*8
alert("Randomnumberintherange0to"+
"7.9999999:\n"+random_number)
</script>
</body>
</html>
10/13
11/13
12/13
<!doctypehtml>
<html>
<body>
<script>
varrandom_number
random_number=Math.random()*50
random_number=Math.floor(random_number)
alert("Randomnumberintherange0to49:"+
random_number)
</script>
</body>
</html>
13/13