Math.round(Math.random()*9+1)的问题,怎么现在才发现...
来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:数学作业 时间:2024/06/17 16:06:44
Math.round(Math.random()*9+1)的问题,怎么现在才发现...
用Math.round(Math.random()*9+1) 模拟一亿次.
从左到右依次对应1到10的出现次数的概率分布如下:
5550975,11110994,11109952,11107453,11113482,11106273,11112448,11113637,11113936,5560850
瞧瞧两头.我以前一直都是用的这句代码来产生随机数=.=
后面我又用 Math.ceil(Math.random() * 10)
和 Math.floor(Math.random() * 10+1) 分别模拟了一亿次,概率分布都很正常~
Math.ceil(Math.random() * 10)
9999674,10002663,9992580,9997330,10002808,10003604,9998316,9999602,10002274,10001149
Math.floor(Math.random() * 10+1)
9998578,10000592,9995001,10003015,9999125,10001943,9999776,9999089,10002336,10000545
其实不用模拟一亿次,模拟1000次就可以看出来了.
用Math.round(Math.random()*9+1) 模拟一亿次.
从左到右依次对应1到10的出现次数的概率分布如下:
5550975,11110994,11109952,11107453,11113482,11106273,11112448,11113637,11113936,5560850
瞧瞧两头.我以前一直都是用的这句代码来产生随机数=.=
后面我又用 Math.ceil(Math.random() * 10)
和 Math.floor(Math.random() * 10+1) 分别模拟了一亿次,概率分布都很正常~
Math.ceil(Math.random() * 10)
9999674,10002663,9992580,9997330,10002808,10003604,9998316,9999602,10002274,10001149
Math.floor(Math.random() * 10+1)
9998578,10000592,9995001,10003015,9999125,10001943,9999776,9999089,10002336,10000545
其实不用模拟一亿次,模拟1000次就可以看出来了.
![Math.round(Math.random()*9+1)的问题,怎么现在才发现...](/uploads/image/z/1881241-25-1.jpg?t=Math.round%28Math.random%28%29%2A9%2B1%29%E7%9A%84%E9%97%AE%E9%A2%98%2C%E6%80%8E%E4%B9%88%E7%8E%B0%E5%9C%A8%E6%89%8D%E5%8F%91%E7%8E%B0...)
ound()方法通俗的说就是四舍五入,也就是生成的结果在1-1.4.之间就等于1,
1.5-2.4.之间等于2
.
9.5-10之间等于10
所以头尾出现的分布区间只有其他数字的一半,你现在得到的结果很正常
1.5-2.4.之间等于2
.
9.5-10之间等于10
所以头尾出现的分布区间只有其他数字的一半,你现在得到的结果很正常
Math.round(Math.random()*9+1)的问题,怎么现在才发现...
Math.random()问题
urlx = Math.floor(Math.random()*799)+1; 怎么改成200-500之间的随机数!
math.round()问题
math.random
math random *
关于Math.random的语句,
Math.floor(Math.random() * 7 +
s=(int)(Math.random()*(g-k)+k); 是不是math.random()*的意思是随即0--1之
Math.ceil(Math.random()*1E5).toString(36)
onClipEvent(sd.onLoad){ var k = Math.round(Math.random()*50)
Math.random是什么意思