gstein      99/11/26 11:43:53

  Modified:    src/modules/standard mod_rewrite.c
  Log:
  jumped the gun on that previous commit. rand()'s lower-order bits may not
  be uniformly random. using floating point will use all the bits.
  
  Revision  Changes    Path
  1.152     +7 -1      apache-1.3/src/modules/standard/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
  retrieving revision 1.151
  retrieving revision 1.152
  diff -u -r1.151 -r1.152
  --- mod_rewrite.c     1999/11/26 19:31:21     1.151
  +++ mod_rewrite.c     1999/11/26 19:43:50     1.152
  @@ -3048,7 +3048,13 @@
   static int rewrite_rand(int l, int h)
   {
       rewrite_rand_init();
  -    return rand() % (h - l + 1) + l;
  +
  +    /* Get [0,1) and then scale to the appropriate range. Note that using
  +     * a floating point value ensures that we use all bits of the rand()
  +     * result. Doing an integer modulus would only use the lower-order bits
  +     * which may not be as uniformly random.
  +     */
  +    return ((double)(rand() % RAND_MAX) / RAND_MAX) * (h - l + 1) + l;
   }
   
   static char *select_random_value_part(request_rec *r, char *value)
  
  
  

Reply via email to