weighted-random
Select randomly from a list of weighted values.
Usage
var weightedRandom = ; var movies = rating: 92 title: 'The Dark Knight' rating: 87 title: 'Inception' rating: 80 title: 'Jurassic Park' ; var weights = movies; // [9.2, 8.7, 8.0] var selectionIndex = ; // 0, 1, or 2 var whatToWatch = moviesselectionIndextitle;// About 36% of the time, we'll watch The Dark Knight.// About 34% of the time, we'll watch Inception.// About 31% of the time, we'll watch Jurassic Park.
License
Copyright © 2015 Brandon Mills. All rights reserved. Licensed under the terms of the MIT license, the full text of which is available in LICENSE.