1.得到一个两数之间的随机数 function getRandom(min,max){ return Math.random()*(max-min)+min; //返回的是一个非整数小于两个实参之间的浮点型的随机值。 } getRandom(3,10);
2.得到一个两数之间的随机整数 function getRandom(min,max){ return Math.floor(Math.random()*(max-min))+min; //返回的是一个向下取整的不包含两个实参的随机整数。 } getRandom(3,10);
3.得到一个两数之间的随机整数,包括两个数在内 function getRandom(min,max){ return Math.floor(Math.random()*(max-min+1))+min; //返回的是一个向下取整包含两个实参的随机整数 } getRandom(3,10);
|
|
来自: python_lover > 《待分类》