📜  如何在 JavaScript 代码示例中生成随机数

📅  最后修改于: 2022-03-11 15:01:30.762000             🧑  作者: Mango

代码示例6
//To genereate a number between 0-1 - > this will give you float 0.1569491123 - 0.98799941612
Math.random();
// Generated number can be rounded with -> Math.floor
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.