Standard random numbers generator.

The random number generator generates gaussian random numbers with zero mean and standard deviation of one. The generator implements polar form of the Box-Muller transformation.

The generator uses UniformOneGenerator generator as a base to generate random numbers.

Sample usage:

// create instance of random generator IRandomNumberGenerator generator = new StandardGenerator( ); // generate random number float randomNumber = generator.Next( );
Inheritance: IRandomNumberGenerator
示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianGenerator"/> class.
        /// </summary>
        ///
        /// <param name="mean">Mean value.</param>
        /// <param name="stdDev">Standard deviation value.</param>
        /// <param name="seed">Seed value to initialize random numbers generator.</param>
        ///
        public GaussianGenerator(double mean, double stdDev, int seed)
        {
            this.mean   = mean;
            this.stdDev = stdDev;

            rand = new StandardGenerator( );
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianGenerator"/> class.
        /// </summary>
        ///
        /// <param name="mean">Mean value.</param>
        /// <param name="stdDev">Standard deviation value.</param>
        /// <param name="seed">Seed value to initialize random numbers generator.</param>
        ///
        public GaussianGenerator(float mean, float stdDev, int seed)
        {
            this.mean   = mean;
            this.stdDev = stdDev;

            rand = new StandardGenerator(seed);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianGenerator"/> class.
        /// </summary>
        /// 
        /// <param name="mean">Mean value.</param>
        /// <param name="stdDev">Standard deviation value.</param>
        /// <param name="seed">Seed value to initialize random numbers generator.</param>
        /// 
        public GaussianGenerator( float mean, float stdDev, int seed )
        {
            this.mean   = mean;
            this.stdDev = stdDev;

            rand = new StandardGenerator( seed );
        }
 /// <summary>
 /// Set seed of the random numbers generator.
 /// </summary>
 /// 
 /// <param name="seed">Seed value.</param>
 /// 
 /// <remarks>Resets random numbers generator initializing it with
 /// specified seed value.</remarks>
 /// 
 public void SetSeed( int seed )
 {
     rand = new StandardGenerator( seed );
 }
示例#5
0
 /// <summary>
 /// Set seed of the random numbers generator.
 /// </summary>
 ///
 /// <param name="seed">Seed value.</param>
 ///
 /// <remarks>Resets random numbers generator initializing it with
 /// specified seed value.</remarks>
 ///
 public void SetSeed(int seed)
 {
     rand = new StandardGenerator(seed);
 }
示例#6
0
        /// <summary>
        ///   Generates a random vector of observations from the current distribution.
        /// </summary>
        /// <param name="samples">The number of samples to generate.</param>
        /// <returns>A random vector of observations drawn from this distribution.</returns>
        public double[][] Generate(int samples)
        {
            var r = new StandardGenerator();
            double[,] A = chol.LeftTriangularFactor;

            var data = new double[samples][];
            for (int i = 0; i < data.Length; i++)
            {
                var sample = new double[Dimension];
                for (int j = 0; j < sample.Length; j++)
                    sample[j] = r.Next();

                data[i] = A.Multiply(sample).Add(Mean);
            }

            return data;
        }