Math.random() 會回傳 0 到 1 之間的偽隨機數,常用於隨機抽取、驗證碼與動畫效果。
var n = Math.random(); document.write(n);
若要取得某範圍內的整數,可再搭配 floor() 或 ceil() 換算。