MINOR: sample: make all bits random on the rand() sample fetch
The rand() sample fetch supports being limited to a certain range, but it only uses 31 bits and scales them as requested, which means that when the requested output range is larger than 31 bits, the least significant one is not random and may even be constant. Let's make use of the whole 32 bits now that we have access ot them.
This commit is contained in:
parent
5a6d3e797e
commit
aa8bbc12dd
@ -3124,11 +3124,11 @@ smp_fetch_thread(const struct arg *args, struct sample *smp, const char *kw, voi
|
||||
static int
|
||||
smp_fetch_rand(const struct arg *args, struct sample *smp, const char *kw, void *private)
|
||||
{
|
||||
smp->data.u.sint = ha_random();
|
||||
smp->data.u.sint = ha_random32();
|
||||
|
||||
/* reduce if needed. Don't do a modulo, use all bits! */
|
||||
if (args && args[0].type == ARGT_SINT)
|
||||
smp->data.u.sint = (smp->data.u.sint * args[0].data.sint) / ((u64)RAND_MAX+1);
|
||||
smp->data.u.sint = ((u64)smp->data.u.sint * (u64)args[0].data.sint) >> 32;
|
||||
|
||||
smp->data.type = SMP_T_SINT;
|
||||
smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user