add numerical recipes library
This commit is contained in:
28
lib/nr/k_and_r/recipes/ran0.c
Normal file
28
lib/nr/k_and_r/recipes/ran0.c
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#define IA 16807
|
||||
#define IM 2147483647
|
||||
#define AM (1.0/IM)
|
||||
#define IQ 127773
|
||||
#define IR 2836
|
||||
#define MASK 123459876
|
||||
|
||||
float ran0(idum)
|
||||
long *idum;
|
||||
{
|
||||
long k;
|
||||
float ans;
|
||||
|
||||
*idum ^= MASK;
|
||||
k=(*idum)/IQ;
|
||||
*idum=IA*(*idum-k*IQ)-IR*k;
|
||||
if (*idum < 0) *idum += IM;
|
||||
ans=AM*(*idum);
|
||||
*idum ^= MASK;
|
||||
return ans;
|
||||
}
|
||||
#undef IA
|
||||
#undef IM
|
||||
#undef AM
|
||||
#undef IQ
|
||||
#undef IR
|
||||
#undef MASK
|
||||
Reference in New Issue
Block a user