randomexample

来源:互联网 发布:送货统计软件 编辑:程序博客网 时间:2024/06/05 07:10

 <html>
<head>
<title>Example</title>
</head>
<body>
<script type="text/javascript">
function selectFrom(iFirstValue, iLastValue) {
    var iChoices = iLastValue - iFirstValue + 1;
    return Math.floor(Math.random() * iChoices + iFirstValue);
}

//select from between 2 and 10
var iNum = selectFrom(2, 10);

var aColors = ["red", "green", "blue", "yellow", "black", "purple", "brown"];
var sColor = aColors[selectFrom(0, aColors.length-1)];

alert(sColor);
</script>
 
</body>
</html>