Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Aug 2014 11:39:30 +0300
From:      Vitaly Magerya <vmagerya@gmail.com>
To:        Chenguang Li <horus.li@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: On changing rand(3) to random(3) in awk(1)
Message-ID:  <54003C42.1070309@gmail.com>
In-Reply-To: <78248D53-D8B6-4135-B900-74E0047F92F1@gmail.com>
References:  <F70B9462-0898-47EF-AF83-47509F21F84E@gmail.com> <53FEFBB8.5040305@gmail.com> <20140828131526.GA2385@straylight.m.ringlet.net> <5C40F611-22EB-49E4-8925-37922E771C0F@gmail.com> <53FF574E.1090108@gmail.com> <78248D53-D8B6-4135-B900-74E0047F92F1@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54003C42.1070309>