--- id: cf1111c1c12feddfaeb2bdef title: Generate Random Whole Numbers within a Range challengeType: 1 videoUrl: '' localeTitle: Gerar números inteiros aleatórios dentro de um intervalo --- ## Description
Em vez de gerar um número aleatório entre zero e um dado número, como fizemos antes, podemos gerar um número aleatório que esteja dentro de um intervalo de dois números específicos. Para fazer isso, definiremos um número mínimo min e um número máximo max . Aqui está a fórmula que vamos usar. Tome um momento para lê-lo e tente entender o que este código está fazendo: Math.floor(Math.random() * (max - min + 1)) + min
## Instructions
Crie uma função chamada randomRange que randomRange um intervalo myMin e myMax e retorne um número aleatório que seja maior ou igual a myMin e seja menor ou igual a myMax , inclusive.
## Tests
```yml tests: - text: 'O menor número aleatório que pode ser gerado por randomRange deve ser igual ao seu número mínimo, myMin .' testString: 'assert(calcMin === 5, "The lowest random number that can be generated by randomRange should be equal to your minimum number, myMin.");' - text: 'O maior número aleatório que pode ser gerado por randomRange deve ser igual ao seu número máximo, myMax .' testString: 'assert(calcMax === 15, "The highest random number that can be generated by randomRange should be equal to your maximum number, myMax.");' - text: 'O número aleatório gerado por randomRange deve ser um inteiro, não um decimal.' testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by randomRange should be an integer, not a decimal.");' - text: randomRange deve usar myMax e myMin e retornar um número aleatório no seu intervalo. 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 ```