【实用】在javascript中math.random()如何生成指定范围数值的随机数
用这个:
代码语言:javascript代码运行次数:0运行复制min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);用parseInt(Math.random() * (max - min + 1) + min)不太行
用这个:
代码语言:javascript代码运行次数:0运行复制min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);用parseInt(Math.random() * (max - min + 1) + min)不太行
发布评论