>> r = (uint64) (pg_erand48(random_state.xseed) * size);
>>
>> I do not understand why the random values are multiplied by anything in
>> the first place…
>
> These are just random integers in the range [0,mask] and [0,size-1],
> formed in exactly the same way as getrand().
Indeed, erand returns a double, this was the part I was missing. I did not
realize that you had switched to doubles in your approach.
I think that permute should only use integer operations. I'd suggest to
use one of the integer variants instead of going through a double
computation and casting back to int. The internal state is based on
integers, I do not see the added value of going through floats, possibly
enduring floating point issues (undeflow, rounding, normalization,
whatever) on the way, whereas from start to finish we just need ints.
See attached v27 proposal.
I still think that *rand48 is a poor (relatively small state) and
inefficient (the implementation includes packing and unpacking 16 bits
ints to build a 64 bits int) choice.
--
Fabien.