Beta
Random Value in a Weighted List
Description:
Write a function that, given a list of weighted values, will return a random value using the weights to determine the probability of each value being returned.
Example:
const values = ['a','b','c','d','e'];
const weights = [ 1, 2, 3, 4, 5 ];
const randomValue = weightedRandom(values, weights);
In this example the probability of each value being selected would be as follows:
a
: 0.066 ( 1/15 )b
: 0.133 ( 2/15 )c
: 0.2 ( 3/15 )d
: 0.266 ( 4/15 )e
: 0.333 ( 5/15 )
Algorithms
Similar Kata:
Stats:
Created | Apr 10, 2017 |
Published | Apr 11, 2017 |
Warriors Trained | 146 |
Total Skips | 25 |
Total Code Submissions | 504 |
Total Times Completed | 38 |
JavaScript Completions | 38 |
Total Stars | 6 |
% of votes with a positive feedback rating | 71% of 21 |
Total "Very Satisfied" Votes | 11 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 20 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 1 kyu |
Lowest Assessed Rank | 8 kyu |