On Fri, Sep 06, 2019 at 11:04:44AM +0200, Tim Düsterhus wrote:
> Willy,
> Luca,
> 
> Am 06.09.19 um 05:17 schrieb Willy Tarreau:
> >>     smp->data.type = SMP_T_STR;
> >>     smp->flags = SMP_F_MAY_CHANGE;
> 
> Comparing this with the time fetches I believe there is 'SMP_F_VOL_TEST'
> missing, no?

Yep good point.

Also RAND_MAX is not the same on all platforms. We're used to having 31
bits on Linux, it's 15 bits only on others like Windows. I think we'd
need to preload 128 bits of random into local variables based on RAND_MAX
then use these variables to produce the output. It could be something more
or less like this :

   uint32_t rnd[4] = { 0, 0, 0, 0 };
   uint64_t last = 0;
   int byte = 0;
   int bits = 0;

   while (byte < 4) {
       while (bits < 32) {
          last |= (uint64_t)random() << bits;
          bits += my_flsl(RAND_MAX);
       }
       rnd[byte++] = last;
       last >>= 32;
       bits  -= 32;
   }

With something like this (modulo the bugs I wrote) you should end up
with 128 bits available in rnd[] regardless of RAND_MAX. 

Willy

Reply via email to