-
Math.random()
; 結(jié)果為0-1間的一個(gè)隨機(jī)數(shù)(包括0,不包括1) -
Math.floor(num)
; 參數(shù)num為一個(gè)數(shù)值惨缆,函數(shù)結(jié)果為num的整數(shù)部分伍掀。 -
Math.round(num)
; 參數(shù)num為一個(gè)數(shù)值禽笑,函數(shù)結(jié)果為num四舍五入后的整數(shù)株茶。 -
Math.ceil(n)
; 返回大于等于n的最小整數(shù)恕洲。
- 用
Math.ceil(Math.random()*10)
;時(shí)塔橡,主要獲取1到10的隨機(jī)整數(shù),取0的幾率極小霜第。 - 用
Math.round(Math.random())
;可均衡獲取0到1的隨機(jī)整數(shù)葛家。 - 用
Math.round(Math.random()*10)
;時(shí),可基本均衡獲取0到10的隨機(jī)整數(shù)泌类,其中獲取最小值0和最大值10的幾率少一半癞谒。 - 用
Math.floor(Math.random()*10)
;時(shí),可均衡獲取0到9的隨機(jī)整數(shù)刃榨。 - 用
Math.floor(Math.random()*50+50)
;時(shí)弹砚,可均衡獲取50到100的隨機(jī)整數(shù)。