Skip to content

Instantly share code, notes, and snippets.

@Nexuist
Last active August 20, 2017 23:23
Show Gist options
  • Save Nexuist/ea03d3cad22ab8d812d04d009e650904 to your computer and use it in GitHub Desktop.
Save Nexuist/ea03d3cad22ab8d812d04d009e650904 to your computer and use it in GitHub Desktop.
// https://stackoverflow.com/a/11935263 - Thanks Tim!
function getRandomSubarray(arr, size) {
var shuffled = arr.slice(0), i = arr.length, temp, index;
while (i--) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(0, size);
}
const luckyUsers = getRandomSubarray(eligible, 25);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment