1. 程式人生 > >js生成隨機數

js生成隨機數

包含 title round pos 隨機數 art set write itl

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JS隨機數測試</title>
</head>
<body>
<script>
document.write(Math.random());//生成一個0~1之間的非常多位數的隨機小數
</script>
<br>
<script>
document.write(Math.round(Math.random()*9+1));//生成一個1~10(包含1和10)的隨機整數
</script>
<br>
<script>
document.write(Math.round(Math.random()*99+1));//生成一個1~100(包含1和100)的隨機整數
</script>
</body>
</html>

js生成隨機數