From: hackbard Date: Wed, 19 Mar 2003 16:22:00 +0000 (+0000) Subject: random values X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f463ab26135aa2850eee73b75f11103dd5f52a40;p=physik%2Fmorpheus.git random values --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4f1c9c9 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +# Makefile of ivac + +INCLUDEDIR = /usr/include + +CFLAGS = -DDEBUG -O3 -Wall -I/usr/include/directfb +LIBS = -L/usr/lib/directfb-0.9.15 -ldirectfb + +OBJS = random.o +OBJS2 = morpheus + +morpheus: $(OBJS) + $(CC) -o $@ $(OBJS) $(LIBS) main.c +all: morpheus + +clean: + rm $(OBJS) $(OBJS2) diff --git a/defines.h b/defines.h new file mode 100644 index 0000000..2e399a4 --- /dev/null +++ b/defines.h @@ -0,0 +1,24 @@ +/* + * morpheus - defines.h + * + * default parameters and program defines + * + */ + +#define DEFAULT_X_SEG 50 +#define DEFAULT_Y_SEG 50 +#define DEFAULT_Z_SEG 100 + +#define DEFAULT_SLOPE_CC 1 +#define DEFAULT_START_CC 0 + +/* program defines, dont touch ;) */ + +#ifdef DEBUG + #define DEBUG 1 +#else + #define DEBUG 0 +#endif + +#define printfd(fmt,args...) if(DEBUG) printf(fmt,##args); + diff --git a/main.c b/main.c index a030dd6..cf2a703 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,85 @@ * * refs: * - J. K. N. Lindner. Habilationsschrift, Universitaet Augsburg. - * - Maik Häberlen. Diplomarbeit, Universitaet Augsburg. + * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg. */ +#include +#include +#include "defines.h" + +/* global variables */ +int sum_z_segments; + +int usage() +{ + puts("usage:"); + puts("-h: help"); + puts("-a \t slope of C concentration with depth (default 1)"); + puts("-c \t concentration at depths 0 (default 0)"); + puts("-x \t # x segments (default 50)"); + puts("-y \t # y segments (default 50)"); + puts("-z \t # z segments (default 100)"); + return -23; +} + +int main(int argc,char **argv) { + int x_seg,y_seg,z_seg; /* amount of segments */ + int x,y,z; /* segments */ + int i; /* for counting */ + int slope_cc,start_cc; /* C concentration: slope, c(0) */ + + /* default values */ + x_seg=DEFAULT_X_SEG-1; + y_seg=DEFAULT_Y_SEG-1; + z_seg=DEFAULT_Z_SEG-1; + slope_cc=DEFAULT_SLOPE_CC; + start_cc=DEFAULT_START_CC; + + /* parse command args */ + for(i=1;i %d\n",sum_z_segments); + + + /* testing ... */ + + for(i=0;i<100;i++) + { + x=rand_get(x_seg); + y=rand_get(y_seg); + z=rand_get_lgp(slope_cc,start_cc); + printf ("x=%d y=%d z=%d\n",x,y,z); + } + return 23; +} diff --git a/random.c b/random.c new file mode 100644 index 0000000..73e69f5 --- /dev/null +++ b/random.c @@ -0,0 +1,27 @@ +/* + * random.c - functions to get random values + * + */ + +#include +#include +#include "defines.h" + +extern int sum_z_segments; + +/* return random integer between 0 - max */ +int rand_get(int max) { + return((int) (rand() * (max*1.0/RAND_MAX)) ); +} + +/* get z value (linear growth of probability with depths) */ +int rand_get_lgp(int slope_cc,int start_cc) { + int z,i; + z=rand_get(sum_z_segments); + for(i=0;;i++) { + z-=i*slope_cc; + if(z<=0) break; + } + return i; +} +