예제 #1
0
        /// <summary>
        /// Take a sample from the distribution, using the provided <see cref="IRandomSource"/> as the source of entropy.
        /// </summary>
        /// <returns>A random sample.</returns>
        public double Sample(IRandomSource rng)
        {
            if (_sample.HasValue)
            {
                double x = _sample.Value;
                _sample = null;
                return(x);
            }

            // Note. The Box-Muller transform generates samples in pairs.
            (double x1, double x2) = BoxMullerGaussian.Sample(rng, _mean, _stdDev);

            // Return the first sample and store the other for future use.
            _sample = x2;
            return(x1);
        }
예제 #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)
 {
     BoxMullerGaussian.Sample(rng, buf);
 }
예제 #3
0
 /// <summary>
 /// Fill a span with samples from the distribution.
 /// </summary>
 /// <param name="span">The span to fill with samples.</param>
 public void Sample(Span <double> span)
 {
     BoxMullerGaussian.Sample(_rng, span);
 }
예제 #4
0
 /// <summary>
 /// Fill an array with samples from the distribution.
 /// </summary>
 /// <param name="buf">The array to fill with samples.</param>
 public void Sample(double[] buf)
 {
     BoxMullerGaussian.Sample(_rng, buf);
 }
 /// <summary>
 /// Fill a span with 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 <double> span, IRandomSource rng)
 {
     BoxMullerGaussian.Sample(rng, span);
 }