0是最小值,N是最大值,N是給定的,求個演算法
uj5u.com熱心網友回復:
Math.round((max - min) * Math.random() + min)uj5u.com熱心網友回復:
function random(n){ return Math.round(Math.random()*n) }uj5u.com熱心網友回復:
習慣上,更喜歡用Math.floor
uj5u.com熱心網友回復:
因為Math.random()回傳的是一個大于等于0,但小于1的亂數。如果在這里使用Math.floor向下取整。那最大數將永遠不會出現。
比如取0~5之間,除非你希望得到的數是不包含5。否則是不能使用Math.floor的
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/276873.html
標籤:JavaScript
上一篇:大佬,救急
