js生成随机数

来源:互联网 发布:韩春雨 专业评价 知乎 编辑:程序博客网 时间:2024/04/30 00:09
<!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>
1 0
原创粉丝点击