/// <summary> /// Construct with the given distribution and a random source. /// </summary> /// <param name="max">Maximum absolute value.</param> /// <param name="signed">Indicates if the distribution interval includes negative values.</param> /// <param name="rng">Random source.</param> public UniformDistributionSampler(double max, bool signed, IRandomSource rng) { _max = max; _signed = signed; _rng = rng; // Note. We predetermine which of these two function variants to use at construction time, // thus avoiding a branch on each invocation of Sample() (i.e. this is a micro-optimization). if (signed) { _sampleFn = (r) => UniformDistribution.SampleSigned(r, _max); } else { _sampleFn = (r) => UniformDistribution.Sample(r, _max); } }