Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Created August 30, 2022 17:48
Show Gist options
  • Save Angelfire/826f8e441549234015fe92a0ce68bf16 to your computer and use it in GitHub Desktop.
Save Angelfire/826f8e441549234015fe92a0ce68bf16 to your computer and use it in GitHub Desktop.
Get x random items from an array
function getRandomArrayItems(list, neededElements) {
const result = []
for (let i = 0; i < neededElements; i++) {
result.push(list[Math.floor(Math.random() * list.length)])
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment