예제 #1
0
        /// <summary>
        ///     [Thread-Unsafe] Get single normal distribution random value of <see cref="double"/>.
        /// </summary>
        /// <returns></returns>
        public double NextNorm64()
        {
            var x = NextFloat64();
            var y = NextFloat64();

            return(NdMath.Sqrt(-2 * NdMath.Log(x)) * NdMath.Cos(2 * NdMath.PI <double>() * y));
        }
예제 #2
0
        /// <summary>
        ///     [Thread-Unsafe] Get multiple normal distribution random values of <see cref="double"/>.
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public double[] NextNorm64(int count)
        {
            var half   = count / 2;
            var retval = NextFloat64(count);

            for (var i = 0; i < half; ++i)
            {
                var j   = i << 1; // 2 * i
                var x   = retval[j];
                var y   = retval[j + 1];
                var mag = NdMath.Sqrt(-2 * NdMath.Log(x));
                var ang = 2 * NdMath.PI <double>() * y;
                retval[j]     = mag * NdMath.Cos(ang);
                retval[j + 1] = mag * NdMath.Sin(ang);
            }

            if ((count & 1) == 1) // count % 2 == 1
            {
                var x = retval[count - 1];
                var y = NextFloat64();
                retval[count - 1] = NdMath.Sqrt(-2 * NdMath.Log(x)) * NdMath.Cos(2 * NdMath.PI <double>() * y);
            }

            return(retval);
        }
예제 #3
0
        /// <summary>
        ///     [Thread-Unsafe] Get single normal distribution random value of <see cref="float"/>.
        /// </summary>
        /// <returns></returns>
        public float NextNorm32()
        {
            var x = NextFloat32();
            var y = NextFloat32();

            return(NdMath.Sqrt(-2 * NdMath.Log(x)) * NdMath.Cos(2 * NdMath.PI <float>() * y));
        }