// "rejfree.c": a C program to illustrate Example 2 of "rejectionfree.tex". // by Jeffrey S. Rosenthal, May 2019 #define METROPOLIS 0 /* 1 for Metropolis, or 0 for uniform rejection-free. */ #define MAXSTATE 10000 #define INITSTATE 100 #define CYCLE 4 #define PRINTFREQ 50 #include #include #include #include double mainpow = 8.0/9; double rempow = 2.0; int main() { int x = INITSTATE, y, i, numits; double pi(), L, R, leftprob; int seedrnd(), ifloor(), gettimeofday(); /* for (i=0; i<100; i++) printf("pi[%d] = %f\n", i, pi(i)); exit(0); */ seedrnd(); numits = 0; while (1) { if (METROPOLIS) { if (drand48()<0.5) y = x-1; else y = x+1; if (drand48()