mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-05 07:41:11 +00:00
beginning to fold in HOD code with jeremy tinker's approval
This commit is contained in:
parent
d8108d3a8e
commit
44cd0eb71f
95 changed files with 21950 additions and 0 deletions
47
c_tools/hod/ran1.c
Normal file
47
c_tools/hod/ran1.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#define IA 16807
|
||||
#define IM 2147483647
|
||||
#define AM (1.0/IM)
|
||||
#define IQ 127773
|
||||
#define IR 2836
|
||||
#define NTAB 32
|
||||
#define NDIV (1+(IM-1)/NTAB)
|
||||
#define EPS 1.2e-7
|
||||
#define RNMX (1.0-EPS)
|
||||
|
||||
float ran1(long *idum)
|
||||
{
|
||||
int j;
|
||||
long k;
|
||||
static long iy=0;
|
||||
static long iv[NTAB];
|
||||
float temp;
|
||||
|
||||
if (*idum <= 0 || !iy) {
|
||||
if (-(*idum) < 1) *idum=1;
|
||||
else *idum = -(*idum);
|
||||
for (j=NTAB+7;j>=0;j--) {
|
||||
k=(*idum)/IQ;
|
||||
*idum=IA*(*idum-k*IQ)-IR*k;
|
||||
if (*idum < 0) *idum += IM;
|
||||
if (j < NTAB) iv[j] = *idum;
|
||||
}
|
||||
iy=iv[0];
|
||||
}
|
||||
k=(*idum)/IQ;
|
||||
*idum=IA*(*idum-k*IQ)-IR*k;
|
||||
if (*idum < 0) *idum += IM;
|
||||
j=iy/NDIV;
|
||||
iy=iv[j];
|
||||
iv[j] = *idum;
|
||||
if ((temp=AM*iy) > RNMX) return RNMX;
|
||||
else return temp;
|
||||
}
|
||||
#undef IA
|
||||
#undef IM
|
||||
#undef AM
|
||||
#undef IQ
|
||||
#undef IR
|
||||
#undef NTAB
|
||||
#undef NDIV
|
||||
#undef EPS
|
||||
#undef RNMX
|
Loading…
Add table
Add a link
Reference in a new issue