2 * random.c - functions to get random values
12 /* global and extern variables */
16 /* return random integer between 0 - max-1 */
20 if(read(random_fd,&rand_int,4)!=4)
22 puts("failed reading 4 bytes of random data");
25 /* cells numbered 0...max-1 */
26 return((u32)(rand_int*(max*1.0/URAND_MAX)));
29 /* get z value (linear growth of probability with depths) */
30 u32 rand_get_lgp(int slope_nel,int start_nel,u32 z_max)
34 weighted_sum_z=z_max*start_nel+slope_nel*gr;
35 z=rand_get(weighted_sum_z)+1; /* +1 as rand_get returns values 0...max-1 */
37 z-=(start_nel+i*slope_nel);
40 return(i-1); /* return values 0...z_cell-1 */