--- id: cf1111c1c12feddfaeb2bdef title: Generate Random Whole Numbers within a Range localeTitle: Generar números enteros al azar dentro de un rango challengeType: 1 --- ## Description
En lugar de generar un número aleatorio entre cero y un número dado como hicimos antes, podemos generar un número aleatorio que se encuentre dentro de un rango de dos números específicos. Para hacer esto, definiremos un número mínimo min y un máximo número max . Aquí está la fórmula que usaremos. Tómese un momento para leerlo e intente entender lo que hace este código: Math.floor(Math.random() * (max - min + 1)) + min
## Instructions
Cree una función llamada randomRange que tome un rango myMin y myMax y devuelva un número aleatorio que sea mayor o igual que myMin , y que sea menor o igual que myMax , inclusive.
## Tests
```yml tests: - text: 'El número aleatorio más bajo que puede ser generado por randomRange debería ser igual a tu 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: "El número aleatorio más alto que puede ser generado por randomRange debería ser igual a tu 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: 'El número aleatorio generado por randomRange debe ser un número entero, no un decimal' testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by randomRange should be an integer, not a decimal.");' - text: ' randomRange debe usar myMax y myMin , y devolver un número aleatorio en tu rango' 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 function randomRange(myMin, myMax) { return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin; } ```