On Wed, Aug 03, 2022 at 08:26:20AM -0600, Theo de Raadt wrote:
> [email protected] wrote:
> 
> > Another way to solve this problem would be to trim the numbers with
> > something like this: if (denom > UINT32_MAX) denom = UINT32_MAX.
> 
> And then document that the program returns incorrect results?
> 
> > >However, using drand48() will mean using a floating point modulus.
> > >We lose the uniform aspect.  I'm not the non-uniform aspects are as
> > >visible in the floating point range.  Succeeding for the full floating
> > >point range is more important than what arc4random_uniform() is trying
> > >to do.  But maybe a uniform version of the double code can grow out of
> > >using the drand48.c code?
> > 
> > Theo, I'm not sure I understand your reasoning. Are you trying to say
> > that we should see if it's possible to create a drand48_uniform? 
> 
> Yes, inside the program.
> 

See this. There's also linked BSD-licensed code that should not be hard
to adapt.

https://mumble.net/~campbell/2014/04/28/uniform-random-float?

Then pick a line if the random number drawn is < 1/denom.

Reply via email to