/// <summary>
 /// Fill an array with samples from the distribution, using the provided <see cref="IRandomSource"/> as the source of entropy.
 /// </summary>
 /// <returns>A random sample.</returns>
 public void Sample(IRandomSource rng, float[] buf)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(rng, _max, buf);
     }
     else
     {
         UniformDistribution.Sample(rng, _max, buf);
     }
 }
 /// <summary>
 /// Fills the provided span with random samples from the 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 <float> span, IRandomSource rng)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(rng, _max, span);
     }
     else
     {
         UniformDistribution.Sample(rng, _max, span);
     }
 }
예제 #3
0
 /// <summary>
 /// Fill an array with samples from the distribution.
 /// </summary>
 public void Sample(float[] buf)
 {
     if (_signed)
     {
         UniformDistribution.SampleSigned(_rng, _max, buf);
     }
     else
     {
         UniformDistribution.Sample(_rng, _max, buf);
     }
 }
예제 #4
0
 /// <summary>
 /// Fills the provided span with random samples from the distribution.
 /// </summary>
 /// <param name="span">The span to fill with samples.</param>
 public void Sample(Span <float> 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(float 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);
            }
        }