--- id: cf1111c1c12feddfaeb2bdef title: Generate Random Whole Numbers within a Range challengeType: 1 videoUrl: '' localeTitle: 生成范围内的随机整数 --- ## Description
我们可以生成一个落在两个特定数字范围内的随机数,而不是像我们之前那样在零和给定数字之间生成一个随机数。为此,我们将定义最小数量min和最大数量max 。这是我们将使用的公式。花一点时间阅读它并尝试理解这段代码在做什么: Math.floor(Math.random() * (max - min + 1)) + min
## Instructions
创建一个名为randomRange的函数,它接受一个范围myMinmyMax并返回一个大于或等于myMin的随机数,并且小于或等于myMax (包括myMax )。
## Tests
```yml tests: - text: randomRange可以生成的最低随机数应该等于你的最小数量myMin 。 testString: 'assert(calcMin === 5, "The lowest random number that can be generated by randomRange should be equal to your minimum number, myMin.");' - text: randomRange可以生成的最高随机数应该等于最大数量myMax 。 testString: 'assert(calcMax === 15, "The highest random number that can be generated by randomRange should be equal to your maximum number, myMax.");' - text: randomRange生成的随机数应该是整数,而不是小数。 testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by randomRange should be an integer, not a decimal.");' - text: randomRange应该同时使用myMaxmyMin ,并在你的范围内返回一个随机数。 testString: 'assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), "randomRange should use both myMax and myMin, and return a random number in your range.");' ```
## Challenge Seed
```js // Example function ourRandomRange(ourMin, ourMax) { return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin; } ourRandomRange(1, 9); // Only change code below this line. function randomRange(myMin, myMax) { return 0; // Change this line } // Change these values to test your function var myRandom = randomRange(5, 15); ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```