Skip to content

Instantly share code, notes, and snippets.

@iammateus
Created July 11, 2022 14:21
Show Gist options
  • Save iammateus/3776ac407a127aa32db5f46e0f5cafa5 to your computer and use it in GitHub Desktop.
Save iammateus/3776ac407a127aa32db5f46e0f5cafa5 to your computer and use it in GitHub Desktop.
JS: generate random integer array of random size
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