added random stuff
authorhackbard <hackbard>
Wed, 25 Feb 2004 11:40:57 +0000 (11:40 +0000)
committerhackbard <hackbard>
Wed, 25 Feb 2004 11:40:57 +0000 (11:40 +0000)
Makefile
check_rand.c [new file with mode: 0644]
general.c
general.h

index 3993f5a..5503811 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS = -O3 -Wall
 LIBS = -L/usr/lib -lm
 
 API = g_plot.o general.o
-OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation kettenbruchentwicklung bessel_1 bessel_2
+OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation kettenbruchentwicklung bessel_1 bessel_2 check_rand
 
 all: $(OBJS)
 
@@ -36,6 +36,9 @@ bessel_1: $(API)
 bessel_2: $(API)
        $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) bessel_2.c
 
+check_rand: $(API)
+       $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) check_rand.c
+
 clean:
        rm $(API) $(OBJS)
 
diff --git a/check_rand.c b/check_rand.c
new file mode 100644 (file)
index 0000000..a99d8ea
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <time.h>
+#include "general.h"
+#include "g_plot.h"
+
+#define STEPS 1000000
+
+int main(int argc,char **argv) {
+       int i;
+
+       my_srand(time(NULL));
+
+       for(i=0;i<STEPS;i++)
+               printf("%f %f\n",my_nrand(),my_nrand());
+
+       return 1;
+}
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);
+}
index dd032a4..16e6419 100644 (file)
--- a/general.h
+++ b/general.h
@@ -3,4 +3,6 @@
 double fak(int l);
 double fak2(int l);
 double absolute_value(double l);
-
+int my_rand(int max);
+int my_srand(int seed);
+double my_nrand(void);