Created
July 11, 2022 14:21
-
-
Save iammateus/3776ac407a127aa32db5f46e0f5cafa5 to your computer and use it in GitHub Desktop.
JS: generate random integer array of random size
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 getRandomIntInclusive(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1) + min); //The maximum is inclusive and the minimum is inclusive | |
} | |
const genArr = () => { | |
const arr = []; | |
for(let i = 0; i < getRandomIntInclusive(0, 100); i++){ | |
arr.push(getRandomIntInclusive(0, 100)) | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment