您的位置:首页 > Web前端 > JavaScript

JavaScript 随机数记录demo

2016-06-08 13:39 211 查看
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>随机数记录</title>
<script>
// alert( Math.round(3.4) );
// 0~1 : Math.round(Math.random());
// 0~10
// alert( Math.round(Math.random()*10) );
// 5~10
// alert( Math.round( Math.random()*5 + 5 ) );
// 10~20
// alert( Math.round( Math.random()*10 + 10 ) );
// 20~100
// alert( Math.round( Math.random()*80 + 20 ) );
// x ~ y
var x = 3;
var y = 49;
// alert( Math.round( Math.random()*(y-x) + x ) );
// 0~x
// alert( Math.round( Math.random()*x) );
// 1~x
alert( Math.ceil( Math.random()*x) );
// 课上小练习:
// 随机产生 100 个从 0 ~ 1000 之间不重复的整数
// var str = 'aaasdlfjhasdlkfs';
// indexOf('s') —— 为数组编写该方法:indexOf('img/1.jpg')
</script>
</head>
<body>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: