/// <summary>
 /// Fills the provided span with random samples from the uniform distribution,
 /// using the provided <see cref="IRandomSource"/> as the source of entropy.
 /// </summary>
 /// <param name="span">The span to fill with samples.</param>
 /// <param name="rng">Random source.</param>
 public void Sample(Span <double> span, IRandomSource rng)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(rng, _max, span);
     }
     else
     {
         UniformDistribution.Sample(rng, _max, span);
     }
 }
示例#2
0
 /// <summary>
 /// Fill an array with samples from the distribution, using the provided <see cref="IRandomSource"/> as the source of entropy.
 /// </summary>
 /// <param name="buf">The array to fill with samples.</param>
 /// <param name="rng">Random source.</param>
 public void Sample(double[] buf, IRandomSource rng)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(rng, _max, buf);
     }
     else
     {
         UniformDistribution.Sample(rng, _max, buf);
     }
 }
 /// <summary>
 /// Fill an array with samples from the distribution.
 /// </summary>
 public void Sample(double[] buf)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(_rng, _max, buf);
     }
     else
     {
         UniformDistribution.Sample(_rng, _max, buf);
     }
 }
 /// <summary>
 /// Fills the provided span with random samples from the uniform distribution.
 /// </summary>
 /// <param name="span">The span to fill with samples.</param>
 public void Sample(Span <double> span)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(_rng, _max, span);
     }
     else
     {
         UniformDistribution.Sample(_rng, _max, span);
     }
 }
        /// <summary>
        /// Construct with the given distribution and a new random source.
        /// </summary>
        /// <param name="max">Uniform distribution max value.</param>
        /// <param name="signed">If true then the distribution interval is (-max, max), otherwise it is [0, max).</param>
        public UniformDistributionStatelessSampler(double max, bool signed)
        {
            _max    = max;
            _signed = signed;

            // 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 = (rng) => UniformDistribution.SampleSigned(rng, _max);
            }
            else
            {
                _sampleFn = (rng) => UniformDistribution.Sample(rng, _max);
            }
        }