/***********************************************************************************
Copyright 2011 Bryan Johnson, Xiaoyue Guan & Charles F. Gammie
mthreed version 1.0 (released Jun 2, 2011)
This file is part of mthreed. mthreed adopts a ZEUS-like scheme to solve
magnetohydrodynamic equations of motion in a shearing sheet. It uses obital
advection to ensure fast and accurate integration in a large shearing box.
You are morally obligated to cite the following paper in his/her
scientific literature that results from use of any part of mthreed:
[1] Johnson, B.M., Guan, X. \& Gammie, C.F. \ 2008, Astrophysical Journal,
Supplement, 177, 373
The latest version of the mthreed is available on our code distribution
website:
http://rainman.astro.uiuc.edu/codelib/
mthreed is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
mthreed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mthreed; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************************/
/* ranc -- return a random deviate between 0 and 1
double ranc(iseed)
* iseed = integer seed for random number generator
- on first call, will seed with iseed (if > 0) or with time(0)
- will reseed anytime iseed > 0
*/
#include "decs.h"
#include
#define N 64
#define RND ( 0x7fff & rand() )
#define MIN ( 2 << 8 )
static P[N] = {
46337, 46327, 46309, 46307, 46301, 46279, 46273, 46271,
46261, 46237, 46229, 46219, 46199, 46187, 46183, 46181,
46171, 46153, 46147, 46141, 46133, 46103, 46099, 46093,
46091, 46073, 46061, 46051, 46049, 46027, 46021, 45989,
45979, 45971, 45959, 45953, 45949, 45943, 45893, 45887,
45869, 45863, 45853, 45841, 45833, 45827, 45823, 45821,
45817, 45779, 45767, 45763, 45757, 45751, 45737, 45707,
45697, 45691, 45677, 45673, 45667, 45659, 45641, 45631
} ;
static int a[N] ;
static int S[N] ;
static int n = 0 ;
int called={1} ;
double ranc(iseed)
int iseed ;
{
int i ;
/* seed the random number generator if first time called or if iseed > 0 */
if (called || iseed != 0) {
called = 0 ;
if (iseed==0)
iseed = time(0) ;
srand(iseed) ;
n = 0 ;
for( i = 0 ; i < N ; i++ ) {
a[i] = 0.0 ;
S[i] = 0.0 ;
while( ( a[i] = RND ) < MIN || a[i] > P[i] - MIN ) ;
while( ( S[i] = RND ) < 1 || a[i] > P[i] - 1 ) ;
}
}
n = S[n] & ( N - 1 ) ;
S[n] = ( S[n] * a[n] ) % P[n] ;
return (double) S[n] / (double) P[n] ;
}
#undef N
#undef RND
#undef MIN