Skip to content

Instantly share code, notes, and snippets.

@nblackburn nblackburn/randomWeight.js
Last active Oct 15, 2018

Embed
What would you like to do?
Select a random item from an array of weights
module.exports = weights => {
let seed = Math.random() * weights.length;
return weights.find(weight => (seed - weight) <= 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.