比如說獲取一個0~10的隨機數(shù),可以想到下面兩種Math.ceil(Math.random()*10);Math.floor(Math.random()*(10+1));但是看到有人說用Math.ceil(Math.random()*10);時取0的幾率極小。用Math.floor(Math.random()*(10+1));時,可均衡獲取0到10的隨機整數(shù)。真的是這樣嗎?那是不是以后獲取隨機數(shù)用floor不用ceil呢?
js獲取隨機數(shù)的問題
ibeautiful
2019-05-22 16:48:50