Last active
March 28, 2021 16:36
-
-
Save ErickAgrazal/d54754e45f17f199064f875360faf30e to your computer and use it in GitHub Desktop.
Generate Array with Pseudo Random Numbers Generated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateArray(size, min=1, max=100){ | |
/* | |
Pseudo Random number array generator. | |
@size: Length of the array that wants to be generated. | |
@min: Minimun value of each number generated. | |
@max: Maximun value of each number generated. | |
Example of usage: | |
const arr = generateArray(10); | |
console.log(arr); | |
-> 82, 33, 85, 17, 32, 84, 86, 58, 82, 91 | |
*/ | |
let arr = []; | |
while(arr.length < size){ | |
const randomNumber = Math.floor(Math.random() * (max-min) + min); | |
arr.push(randomNumber); | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment