Example #1
0
        /// <summary>
        /// Generate next random number.
        /// </summary>
        ///
        /// <returns>Returns next random number.</returns>
        ///
        public float Regenerate( )
        {
            // 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.Regenerate( ) * 2.0f - 1.0f;
                x2 = (float)rand.Regenerate( ) * 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 #2
0
 /// <summary>
 /// Generate next random number
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public float Regenerate( )
 {
     return(-(float)Math.Log(rand.Regenerate( )) / rate);
 }
Example #3
0
 /// <summary>
 /// Generate next random number.
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public float Regenerate( )
 {
     return((float)rand.Regenerate( ) * length + min);
 }