/* immigration-emigration simulation */ #include <stdio.h> #include <stdlib.h> #define MAXTIME 100 #define PRNT_INTVL 10 int main(void) { int ttt, popSizeIncrement, popSize, seed; double alpha, beta; alpha = 0.1; beta = 0.1; popSize = 10; seed = 456739853; srand48(seed); printf("time\tpopSize\n"); for (ttt = 0; ttt < MAXTIME; ttt++) { popSizeIncrement = 0; if(drand48() < alpha) popSizeIncrement = 1; if(drand48() < beta) popSizeIncrement = popSizeIncrement - 1; popSize += popSizeIncrement; if(popSize < 0) popSize = 0; if(ttt % PRNT_INTVL == 0) printf("%4d\t%-4d\n", ttt, popSize); } return(0); }