コード例 #1
0
ファイル: gauss_rnd_bell.c プロジェクト: lonnell/trick
double gauss_rnd_bell(          /* Return: Random number */
                         RAND_GENERATOR * G)
{                                      /* Inout: generator parameters */
    double sample = 0.0;
    double x1, x2;

    switch (G->uniform) {

        case LCG1:                    /* Chose single LCG uniform generator */
            if (G->sigma_range < 1) {

                x1 = uniform_rnd_1(G);
                x2 = uniform_rnd_1(G);

                sample = sqrt(-2 * log(x1)) * cos(2 * M_PI * x2);
            }

            else {
                do {
                    x1 = uniform_rnd_1(G);
                    x2 = uniform_rnd_1(G);

                    sample = sqrt(-2 * log(x1)) * cos(2 * M_PI * x2);
                } while (sample < -G->sigma_range || sample > G->sigma_range);
            }

            break;

        case TRIPLE:                  /* Chose Triple LCG uniform generator */
            if (G->sigma_range < 1) {

                x1 = uniform_rnd_triple(G);
                x2 = uniform_rnd_triple(G);

                sample = sqrt(-2 * log(x1)) * cos(2 * M_PI * x2);
            }

            else {
                do {
                    x1 = uniform_rnd_triple(G);
                    x2 = uniform_rnd_triple(G);

                    sample = sqrt(-2 * log(x1)) * cos(2 * M_PI * x2);

                } while (sample < -G->sigma_range || sample > G->sigma_range);
            }

            break;

    }

    return (sample);
}
コード例 #2
0
ファイル: gauss_rnd_pseudo.c プロジェクト: Arafatk/trick
double gauss_rnd_pseudo(        /* Return: random number */
                           RAND_GENERATOR * G)
{                                      /* Inout: generator parameters */
    double sample = 0.0;
    int i;

    switch (G->uniform) {

        case LCG1:                    /* Chose LCG uniform generator */

            for (i = 0; i < 2 * G->sigma_range; i++) {
                sample += uniform_rnd_1(G);
            }
            sample = (sample - (double) G->sigma_range);

            break;


        case TRIPLE:                  /* Chose Triple LCG uniform generator */

            for (i = 0; i < 2 * G->sigma_range; i++) {
                sample += uniform_rnd_triple(G);
            }
            sample = (sample - (double) G->sigma_range);

            break;
    }
    return (sample);
}