Math.random()是令系統隨機選取大於等於 0.0 且小於 1.0 的偽隨機 double 值
函數返回 min(包含)~ max(不包含)之間的數字:
Math.floor(Math.random() * (max - min) ) + min;
函數返回 min(包含)~ max(包含)之間的數字
Math.floor(Math.random() * (max - min + 1) ) + min;
Math.random()是令系統隨機選取大於等於 0.0 且小於 1.0 的偽隨機 double 值
函數返回 min(包含)~ max(不包含)之間的數字:
Math.floor(Math.random() * (max - min) ) + min;
函數返回 min(包含)~ max(包含)之間的數字
Math.floor(Math.random() * (max - min + 1) ) + min;
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。