Exemplo n.º 1
0
        /// <summary>
        /// Take a sample from the distribution.
        /// </summary>
        /// <returns>A random sample.</returns>
        public float Sample()
        {
            if (_sample.HasValue)
            {
                float x = _sample.Value;
                _sample = null;
                return(x);
            }

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

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