/* this is my general purpose random function * * random numbers are always paramaterized between min and max. * however, the "focus" variable allows an interpolation between * a uniform and gaussian distribution (normal extends * "focus" standard deviations from center and a focus of 0 * is a uniform distribution). */ function focusedRandom(min, max, focus, mean) { if(max === undefined) { max = min; min = 0; } if(focus === undefined) { focus = 1.0; } if(mean === undefined) { mean = (min + max) / 2.0; } if(focus == 0) { return d3.randomUniform(min, max)(); } else if(focus < 0) { focus = -1 / focus; } sigma = (0.5 * (max - min)) / focus; val = d3.randomNormal(mean, sigma)(); if (val > min && val < max) { return val; } return d3.randomUniform(min, max)(); }