From 989192e9fd1c4bd9d0875968b0e34408a4297d4c Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Wed, 10 Feb 2016 12:53:05 -0800 Subject: [PATCH] Make randomize clearer. --- examples/libraries/virtualBaton.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/libraries/virtualBaton.js b/examples/libraries/virtualBaton.js index 13d9abe9e7..63f96a5c1e 100644 --- a/examples/libraries/virtualBaton.js +++ b/examples/libraries/virtualBaton.js @@ -28,11 +28,11 @@ function virtualBatonf(options) { // Answer averages (number +/- variability). Avoids having everyone act in lockstep. function randomize(number, variability) { - var allowedDeviation = number * variability; - var theNumberThatIsTwice = 2; - // random() is (0, 1], averages 0.5. The average of twice that is 1. - var randomDeviation = Math.random() * theNumberThatIsTwice * allowedDeviation; - return number - allowedDeviation + randomDeviation; + var allowedDeviation = number * variability; // one side of the deviation range + var allowedDeviationRange = allowedDeviation * 2; // total range for +/- deviation + var randomDeviation = Math.random() * allowedDeviationRange; + var result = number - allowedDeviation + randomDeviation; + return result; } // Allow testing outside in a harness outside of High Fidelity. // See sourceCodeSandbox/tests/mocha/test/testVirtualBaton.js