最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

生成2个数字之间的随机数?

SEO心得admin59浏览0评论
本文介绍了生成2个数字之间的随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 在Javascript中生成特定范围内的随机数?

我想要生成一个50到100的随机数。

Say I wanted to generate a random number from 50 to 100.

我知道有:

Math.random()

但是我只能找到从1到'x'的方法

but I could only find ways to go from 1 to 'x'

推荐答案

来自 MDN on Math.random() :

// Returns a random integer between min and max // Using Math.round() will give you a non-uniform distribution! function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
发布评论

评论列表(0)

  1. 暂无评论