Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function* random(min, max, breaking) {
while (true) {
let number = parseInt((Math.random() * max) + min);
let value = yield number;
if (value === "stop") {
return number;
}
}
}
let generator = random(0, 10, 5);
console.log(generator.next().value);
console.log(generator.next("stop").value);
console.log(generator.next().value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment