]> hackdaworld.org Git - physik/morpheus.git/commitdiff
fixed new read random condition. changed function variable names.
authorhackbard <hackbard>
Fri, 4 Apr 2003 14:09:48 +0000 (14:09 +0000)
committerhackbard <hackbard>
Fri, 4 Apr 2003 14:09:48 +0000 (14:09 +0000)
random.c

index 5657eedeb9d3663f9941180e39104c2fdce2faa0..b2e11fd1fbc621486c23dccf940514e0ffe7fd18 100644 (file)
--- a/random.c
+++ b/random.c
@@ -17,12 +17,12 @@ extern u32 *rand_buf,*rand_current;
 /* 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;
@@ -32,14 +32,15 @@ u32 rand_get(u32 max)
 }
 
 /* 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 */