diff --git a/test/common/fns/randomVal.js b/test/common/fns/randomVal.js index 67fe0937df..f58dd1ab06 100644 --- a/test/common/fns/randomVal.js +++ b/test/common/fns/randomVal.js @@ -40,12 +40,11 @@ describe('shared.fns.randomVal', () => { let result = randomVal(obj, { user, seed: 100, - randomFunc: randomSpy, + predictableRandom: randomSpy, }); expect(Math.random).to.not.be.called; expect(randomSpy).to.be.calledOnce; - expect(randomSpy).to.be.calledWith(user, 100); expect(result).to.equal(2); }); diff --git a/website/common/script/fns/randomVal.js b/website/common/script/fns/randomVal.js index 1973ad6552..3aab845393 100644 --- a/website/common/script/fns/randomVal.js +++ b/website/common/script/fns/randomVal.js @@ -3,17 +3,17 @@ import _ from 'lodash'; // Get a random property from an object // returns random property (the value) -function randomGenerator (user, seed, providedRandom) { - return providedRandom ? providedRandom(user, seed) : Math.random(); +function trueRandom () { + return Math.random(); } module.exports = function randomVal (obj, options = {}) { let array = options.key ? _.keys(obj) : _.values(obj); - let rand = randomGenerator(options.user, options.seed, options.randomFunc); + let random = (options.predictableRandom || trueRandom)(); array.sort(); - let randomIndex = Math.floor(rand * array.length); + let randomIndex = Math.floor(random * array.length); return array[randomIndex]; };