这是一个JavaScript的Math.random生成随机数函数的使用方法示例代码,自己修改后原创的Math.random函数,自认为用着不错,刷新页面看一下。那个Alert弹窗你用时候自己去掉,这里只是为了演示功能。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html>
<head>
<title>Math.random</title>
<script language="javascript">
function myRandom(iStart,iLast)
var iLength = iLast-iStart+1;
return Math.floor(Math.random()*iLength+iStart);
}
alert( myRandom(2,9));
</script>
</head>
<body>
自己修改后原创的Math.random函数,自认为用着不错,刷新页面看一下。
</body>
</html>