drops are randomly selected, not based on user values fixes #7929

This commit is contained in:
Thomas Gamble
2016-09-10 10:37:15 -07:00
committed by Blade Barringer
parent b54441a637
commit 4d5b6992be
3 changed files with 46 additions and 104 deletions

View File

@@ -1,12 +1,19 @@
import _ from 'lodash';
import predictableRandom from './predictableRandom';
// Get a random property from an object
// returns random property (the value)
function randomGenerator (user, seed, providedRandom) {
return providedRandom ? providedRandom(user, seed) : Math.random();
}
module.exports = function randomVal (user, obj, options = {}) {
let array = options.key ? _.keys(obj) : _.values(obj);
let rand = predictableRandom(user, options.seed);
let rand = randomGenerator(user, options.seed, options.randomFunc);
array.sort();
return array[Math.floor(rand * array.length)];
let randomIndex = Math.floor(rand * array.length);
return array[randomIndex];
};