random values
[physik/morpheus.git] / random.c
1 /*
2  * random.c - functions to get random values
3  *
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "defines.h"
9
10 extern int sum_z_segments;
11
12 /* return random integer between 0 - max */
13 int rand_get(int max) {
14  return((int) (rand() * (max*1.0/RAND_MAX)) );
15 }
16
17 /* get z value (linear growth of probability with depths) */
18 int rand_get_lgp(int slope_cc,int start_cc) {
19  int z,i;
20  z=rand_get(sum_z_segments);
21  for(i=0;;i++) {
22   z-=i*slope_cc;
23   if(z<=0) break;
24  }
25  return i;
26 }
27