C---------------------------------------------------------------------C C Random Number Generator C C---------------------------------------------------------------------C C Uniform pseudo-random number generator; mixed congruential C C type. The function value is a real number on the half-open C C interval [0,1) (i.e., including 0, but not 1). C C---------------------------------------------------------------------C ccc Note to ChEg 698 students: ccc To use: define rranf in your main program as double precision ccc and define iseed as an integer. That is, in your variable ccc declarations, put ccc double precision rranf ccc integer iseed ccc To get a random number, initialize iseed once at the very start of ccc the run. Use a large (7 digit) integer, like your phone number. ccc iseed = 5551212 ccc Then, whenever you put the statement ccc rranf(iseed) ccc you will get a "random" number on [0,1). iseed gets changed by ccc the call, and so if other routines call rranf, they need to have ccc the value of iseed passed to them. If you start over with the ccc same iseed, you will get exactly the same sequence of random ccc numbers (hence, they're not truly random). If you change iseed, ccc though, the sequence will be completely different. In this way, ccc you can generate completely different Markov chains under the same ccc conditions and assess the error in you results. c---------------------------------------------------------------------- function rranf( ISeed ) implicit none real*8 rranf C < PASSED Integer*4 ISeed C < LOCAL Integer*4 ib, ia, ibc, ida, isum, iff, ie, ix, iy, ix2, ix1 ib= ISeed/65536 ia= ISeed - ib*65536 ibc= ib*63253 ida= ia*24301 isum= ibc - 2147483647 + ida If( isum .Le. 0 ) Then isum= isum + 2147483647 Else isum= isum - 1 End If iff= isum/32768 ie= isum - iff*32768 ix= ie + ia iy= 453816691 - 2283*ia ix2= ix/32768 ix1= ix - 32768*ix2 ISeed= ix1*65536 - 2147483647 + iy If( ISeed .Le. 0 ) Then ISeed= ISeed + 2147483647 Else ISeed= ISeed - 1 End If rranf= ISeed*4.65661287524579692410575D-10 Return End