Beispiel #1
0
        /// <summary>
        /// Gets a cauchy distributed random value.
        /// </summary>
        /// <param name="Median">Median of distribution.</param>
        /// <param name="Scale">Scale of distribution.</param>
        /// <returns>Random value.</returns>
        public static double NextDouble(double Median, double Scale)
        {
            if (Scale <= 0)
            {
                throw new ArgumentOutOfRangeException("Must be positive.", nameof(Scale));
            }

            return(Math.Tan(Math.PI * (Uniform.NextDouble() - 0.5)) * Scale + Median);
        }
Beispiel #2
0
        /// <summary>
        /// Gets a normally distributed random value. Distribution has a mean of 0 and standard deviation of 1.
        /// </summary>
        /// <returns>Random value.</returns>
        public static double NextDouble()
        {
            double U1 = Uniform.NextDouble();
            double U2 = Uniform.NextDouble();
            double r  = Math.Sqrt(-2.0 * Math.Log(U1));

            r *= Math.Sin(2.0 * Math.PI * U2);

            return(r);
        }
Beispiel #3
0
        /// <summary>
        /// Gets a laplace distributed random value.
        /// </summary>
        /// <param name="Mean">Mean of distribution.</param>
        /// <param name="Scale">Scale of distribution.</param>
        /// <returns>Random value.</returns>
        public static double NextDouble(double Mean, double Scale)
        {
            double u = Uniform.NextDouble();

            if (u < 0.5)
            {
                return(Mean + Scale * Math.Log(2 * u));
            }
            else
            {
                return(Mean - Scale * Math.Log(2 * (1 - u)));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets a weibull distributed random value.
        /// </summary>
        /// <param name="Shape">Shape of distribution.</param>
        /// <param name="Scale">Scale of distribution.</param>
        /// <returns>Random value.</returns>
        public static double NextDouble(double Shape, double Scale)
        {
            if (Shape <= 0)
            {
                throw new ArgumentOutOfRangeException("Must be positive.", nameof(Shape));
            }

            if (Scale <= 0)
            {
                throw new ArgumentOutOfRangeException("Must be positive.", nameof(Scale));
            }

            return(Math.Pow(-Math.Log(Uniform.NextDouble()), 1 / Shape) * Scale);
        }
Beispiel #5
0
        /// <summary>
        /// Gets a gamma distributed random value.
        /// </summary>
        /// <param name="Shape">Shape of distribution.</param>
        /// <param name="Scale">Scale of distribution.</param>
        /// <returns>Random value.</returns>
        public static double NextDouble(double Shape, double Scale)
        {
            double d, c, x, x2, v, u;

            if (Shape >= 1)
            {
                d = Shape - 1.0 / 3;
                c = 1 / Math.Sqrt(9 * d);

                while (true)
                {
                    do
                    {
                        x = Normal.NextDouble();
                        v = 1 + c * x;
                    }while (v <= 0);

                    v  = v * v * v;
                    u  = Uniform.NextDouble();
                    x2 = x * x;

                    if (u < 1 - .0331 * x2 * x2 || Math.Log(u) < 0.5 * x2 + d * (1 - v + Math.Log(v)))
                    {
                        return(Scale * d * v);
                    }
                }
            }
            else if (Shape <= 0)
            {
                throw new ArgumentOutOfRangeException("Shape must be positive.", nameof(Shape));
            }
            else
            {
                double g = NextDouble(Shape + 1, 1);
                double w = Uniform.NextDouble();
                return(Scale * g * Math.Pow(w, 1 / Shape));
            }
        }
Beispiel #6
0
 /// <summary>
 /// Gets a exponentially distributed random value. Distribution has a mean of 0 and standard deviation of 1.
 /// </summary>
 /// <returns>Random value.</returns>
 public static double NextDouble()
 {
     return(-Math.Log(Uniform.NextDouble()));
 }