admin管理员组

文章数量:1794759

【实用】在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)不太行

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2024-10-12,如有侵权请联系 cloudcommunity@tencent 删除randomjavascriptmathmaxmin

本文标签: 实用在javascript中mathrandom()如何生成指定范围数值的随机数