Next() public method

Generate next random number.
public Next ( ) : double
return double
        /// <summary>
        /// Generate next random number.
        /// </summary>
        ///
        /// <returns>Returns next random number.</returns>
        ///
        public double Next( )
        {
            // check if we can use second value
            if (useSecond)
            {
                // return the second number
                useSecond = false;
                return(secondValue);
            }

            double x1, x2, w, firstValue;

            // generate new numbers
            do
            {
                x1 = rand.Next( ) * 2.0 - 1.0;
                x2 = rand.Next( ) * 2.0 - 1.0;
                w  = x1 * x1 + x2 * x2;
            }while (w >= 1.0);

            w = Math.Sqrt((-2.0 * Math.Log(w)) / w);

            // get two standard random numbers
            firstValue  = x1 * w;
            secondValue = x2 * w;

            useSecond = true;

            // return the first number
            return(firstValue);
        }
        /// <summary>
        /// Generate next random number.
        /// </summary>
        ///
        /// <returns>Returns next random number.</returns>
        ///
        public float Next( )
        {
            // check if we can use second value
            if (useSecond)
            {
                // return the second number
                useSecond = false;
                return(secondValue);
            }

            float x1, x2, w, firstValue;

            // generate new numbers
            do
            {
                x1 = (float)rand.Next( ) * 2.0f - 1.0f;
                x2 = (float)rand.Next( ) * 2.0f - 1.0f;
                w  = x1 * x1 + x2 * x2;
            }while (w >= 1.0f);

            w = (float)Math.Sqrt((-2.0f * Math.Log(w)) / w);

            // get two standard random numbers
            firstValue  = x1 * w;
            secondValue = x2 * w;

            useSecond = true;

            // return the first number
            return(firstValue);
        }
Example #3
0
        public float Next()
        {
            if (useSecond)
            {
                useSecond = false;
                return(secondValue);
            }
            float num;
            float num2;
            float num3;

            do
            {
                num  = rand.Next() * 2f - 1f;
                num2 = rand.Next() * 2f - 1f;
                num3 = num * num + num2 * num2;
            }while (num3 >= 1f);
            num3 = (float)System.Math.Sqrt(-2.0 * System.Math.Log(num3) / (double)num3);
            float result = num * num3;

            secondValue = num2 * num3;
            useSecond   = true;
            return(result);
        }
Example #4
0
 /// <summary>
 /// Generate next random number.
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public float Next( )
 {
     return((float)rand.Next( ) * length + min);
 }
 /// <summary>
 /// Generate next random number
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public float Next( )
 {
     return(-(float)Math.Log(rand.Next( )) / rate);
 }
 /// <summary>
 /// Generate next random number
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public double Next( )
 {
     return(-Math.Log(rand.Next( )) / rate);
 }
Example #7
0
 public float Next()
 {
     return((0f - (float)System.Math.Log(rand.Next())) / rate);
 }
Example #8
0
 /// <summary>
 /// Generate next random number.
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public double Next( )
 {
     return(rand.Next( ) * length + min);
 }