added random stuff
[physik/computational_physics.git] / general.c
index b92f8e8..4f07a36 100644 (file)
--- 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);
+}