[SLOF] [PATCH v2 2/7] libc: Fix the rand() function to return non-zero values

Thomas Huth thuth at redhat.com
Tue Dec 22 23:51:23 AEDT 2015


On 22/12/15 12:59, Segher Boessenkool wrote:
> On Tue, Dec 22, 2015 at 11:08:38AM +0100, Thomas Huth wrote:
>> The rand() function in SLOF's libc has a bug which caused the
>> function to always return zero: The _rand value was shifted left
>> by 16, and then ANDed with 0x7fff. Obviously, the shift operation
>> should be ">>" instead of "<<".
>> And while we're at it, also increase the constant for the
>> multiplaction in there so that more upper bits are affected.
> 
> Have you checked that that is in fact a better random generator?

I haven't done a deep analysis of the "algorithm" (e.g. about the length
of the period when the numbers start to repeat), I just had a look at
the initial outputs when using the standard seed and noticed that the
upper bits did not change that fast.

>From a mathematical point of view, I think both variants are very poor.

> But really, don't bother with any of this, just import a known-good
> random generator?  There must be many with compatible license...

For the current purpose (just to generate a non-zero transaction ID),
the current implementation seems to be good enough for me. But in the
long run, that's certainly a good idea, ... I'd then just like to leave
that decision to pick a compatible implementation to the maintainers of
SLOF.

> I looked over the other patches in the series and nothing stuck out,
> all looks good.

Thanks!

 Thomas



More information about the SLOF mailing list