#include /* Generating pseudo random numbers by a modulo technique: basic idea: new_seed = (a * seed + r) % m This program lets you experiment with different values of a, r and m in order to investigate quality of the pseudo-random sequence Usage: % pseudorandomexpt --- to accept all defaults % pseudorandomexpt M --- to accept all defaults except m % pseudorandomexpt M A --- to accept all defaults except m,a % pseudorandomexpt M A R --- to accept all defaults except m,a,r % pseudorandomexpt M A R S --- to accept no defaults M A R S are new values for m a r s Try it with the defaults. See the problem? Period is ? Try it with pseudorandomexpt 101 19 51. Is it better? Is it good? */ long m = 100; /* is this good? */ long a = 19; /* is this good? */ long r = 51; /* how about this? */ long next(s) long s; { return (a * s + r) % m; } main(argc, argv) int argc; char *argv[]; { long s; int i; char continu; s = 25; if (argc > 1) m = (long) atoi(argv[1]); if (argc > 2) a = (long) atoi(argv[2]); if (argc > 3) r = (long) atoi(argv[3]); if (argc > 4) s = (long) atoi(argv[4]); continu = 'g'; while (continu != 'q') { for (i=0; i<20; i++) { printf("%d ", s); s = next(s); } printf("\n"); printf("Hit q to quit, ENTER to continue > "); continu = getchar(); } getchar(); /* eat the CR/LF */ }