On changing rand(3) to random(3) in awk(1)

Vitaly Magerya vmagerya at gmail.com
Fri Aug 29 08:39:40 UTC 2014


On 2014-08-29 10:12, Chenguang Li wrote:
>> OK, so this part is wrong (and it is wrong in the original sources
>> too): this construction generates 0.0 twice as often as it generates
>> other numbers -- both when random() returns 0 and when it returns
>> RANDOM_MAX. The correct construction is this:
> 
> Yes, I've noticed there's a fairness problem, 0 comes out more often. Since
> the original code is buggy too, do we need to be compatible with it?

I see no reason why we would.

Interestingly enough, GNU awk has this bug as well (and I am entirely
too lazy to report it).

> Thanks for pointing that out, I've modified the gist as your suggestion.

Looks good to me. You might want to open a bug report with that patch,
as it's not clear if any committer is reading this thread.



More information about the freebsd-hackers mailing list