Beispiel #1
0
        public double Next()
        {
            if (isSaved)
            {
                isSaved = false;
                return(saved);
            }

            double
                x = 1.0,
                y = 1.0,
                s = 1.0;

            do
            {
                x = 2 * random.Next() - 1;
                y = 2 * random.Next() - 1;
                s = x * x + y * y;
            } while (s > 1 || s == 0);

            double
                z0 = x * Math.Sqrt(-2.0 * Math.Log(s) / s),
                z1 = y * Math.Sqrt(-2.0 * Math.Log(s) / s);

            saved   = z1;
            isSaved = true;

            return(z0);
        }
Beispiel #2
0
        public double Next()
        {
            int    index  = (int)(K * rand2.Next());
            double result = table[index];

            table[index] = rand1.Next();

            return(result);
        }
Beispiel #3
0
        public double Next()
        {
            double x = 0.0;

            do
            {
                x = random.Next();
            } while (x == 0.0);

            return(-Math.Log(x) / a);
        }
Beispiel #4
0
        public MacLarenRandom(RandomBSV rand1, RandomBSV rand2)
        {
            table = new double[K];

            this.rand1 = rand1;
            this.rand2 = rand2;

            for (int i = 0; i < K; i++)
            {
                table[i] = rand1.Next();
            }
        }
Beispiel #5
0
        public double Next()
        {
            double y = random.Next();

            if (y < 0.5)
            {
                return(1.0 / a * Math.Log(2 * y));
            }
            else
            {
                return(-1.0 / a * Math.Log(2 * (1 - y)));
            }
        }
        public double Next()
        {
            double a = random.Next();

            if (a < pi[0])
            {
                return(distributions[0].Next());
            }
            else
            {
                return(distributions[1].Next());
            }
        }