Skip to content

Instantly share code, notes, and snippets.

@killedbymemory
Created September 17, 2020 14:26
Show Gist options
  • Save killedbymemory/0a88e17dddec6d6c5c552c219aeaee81 to your computer and use it in GitHub Desktop.
Save killedbymemory/0a88e17dddec6d6c5c552c219aeaee81 to your computer and use it in GitHub Desktop.
Bingo!
let genRandom = (max = 10) => {
let exist = [];
const rand = () => Math.ceil(Math.random() * max);
return () => {
if (exist.length === max) {
return;
}
let n = rand();
while (exist.includes(n)) {
n = rand();
}
exist.push(n);
console.log(exist, n);
};
}
let max = 100;
let next = genRandom(max);
for (var i = 0; i < max; i++) next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment