X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fcomputational_physics.git;a=blobdiff_plain;f=general.c;fp=general.c;h=4f07a36314d21dfc3aa286a7abe9be8c73882f69;hp=b92f8e8efd3b059970a37300ff7997e8741c3eae;hb=67357f3ce55120bd52bf941ed664ba6d52dbf19d;hpb=1f172cee5738b87844ca151b22a62bdbdff7b7f5 diff --git a/general.c b/general.c index b92f8e8..4f07a36 100644 --- a/general.c +++ b/general.c @@ -18,3 +18,33 @@ double fak2(int l) { double absolute_value(double l) { return l<0?-l:l; } + +#define __A 48271 +#define __Q 44488 +#define __R 3399 +#define __M ((2<<31)-1) +#define NRAND_MAX + +/* global variable -- I_{k+1} dedpends on I_{k} */ +static int idum=123456; + +int my_rand(int max) { + int h; + h=idum/__Q; + idum=__A*(idum-h*__Q)-h*__R; + if(idum<0) idum+=__M; + return(idum*(max/__M)); +} + +int my_srand(int seed) { + printf("debug: seed = %d\n",seed); + return(idum=seed); +} + +double my_nrand(void) { + int h; + h=idum/__Q; + idum=__A*(idum-h*__Q)-h*__R; + if(idum<0) idum+=__M; + return(1.0*idum/__M); +}