From 331993c1dfafa14282fbc9f3a11b3ff189bcc78f Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 24 Sep 2016 21:25:14 -0500 Subject: [PATCH] refactor: remove seeding from randomVal --- test/common/fns/randomVal.js | 3 +-- website/common/script/fns/randomVal.js | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) 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]; };