LCG random number generation algorithm

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char** argv)
{
    int n = 300000000;
    double U;
    int random_num;

    srand (Time (NULL));   // initialize the random number seed 
    for ( int I = 0 ; I < 10 ; I ++ )
    {
        The U- = ( Double ) RAND () / and RAND_MAX; // generate a random number between [0,1] 
        random_num = ( int ) ((n-- . 1 ) * the U-+ 0.5 ); // generate [0, n-1 a random number between] 
        the printf ( " % D " , random_num);
    }

    return 0;
}

 

Guess you like

Origin www.cnblogs.com/lovebay/p/12369983.html