/* return random integer between 0 - max-1 */
u32 rand_get(u32 max)
{
- if(rand_current==rand_buf+RAND_BUF_SIZE)
+ if(rand_current>=rand_buf+(RAND_BUF_SIZE/sizeof(u32)))
{
printfd("debug: reading new random bytes\n");
if(read(random_fd,rand_buf,RAND_BUF_SIZE)!=RAND_BUF_SIZE)
{
- puts("failed reading viel bytes of random data");
+ puts("failed reading 1 mega bytes of random data");
return -23;
}
rand_current=rand_buf;
}
/* get z value (linear growth of probability with depths) */
-u32 rand_get_lgp(int slope_nel,int start_nel,u32 z_max)
+u32 rand_get_lgp(int slope,int start,u32 z_max)
{
int z;
u32 i,weighted_sum_z;
- weighted_sum_z=z_max*start_nel+slope_nel*gr;
+ weighted_sum_z=z_max*start+slope*gr;
z=rand_get(weighted_sum_z)+1; /* +1 as rand_get returns values 0...max-1 */
- for(i=1;;i++) {
- z-=(start_nel+i*slope_nel);
+ for(i=1;;i++)
+ {
+ z-=(start+i*slope);
if(z<=0) break;
}
return(i-1); /* return values 0...z_cell-1 */