Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Aug 2014 15:59:07 -0400
From:      Lowell Gilbert <freebsd-questions-local@be-well.ilk.org>
To:        Chenguang Li <horus.li@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Ask for opinion: changing rand(3) to random(3) in awk(1)
Message-ID:  <44mwapn1pw.fsf@lowell-desk.lan>
In-Reply-To: <CEB89C77-7426-481C-ACCA-284C86B168A6@gmail.com> (Chenguang Li's message of "Wed, 27 Aug 2014 15:30:56 %2B0800")
References:  <CEB89C77-7426-481C-ACCA-284C86B168A6@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Chenguang Li <horus.li@gmail.com> writes:

> Hi guys,
>
> After encountering the same problem posted here[1] (awk's rand() not
> "random" enough), I did some research. It[2] shows that awk(1) in OSX
> is currently using random(3) instead of rand(3), the same in gawk(1).
>
> Changing rand(3) to random(3) only requires modifying a few lines of code, but will result in better random number generation.
>
> So why not? :)
>
> [1] https://forums.freebsd.org/viewtopic.php?&t=6456
> [2] http://www.opensource.apple.com/source/awk/awk-18/src/run.c

I had thought about that a few years ago, but I didn't have any cases
where it mattered. Note that your example (footnote 1) is *not* such a
case. The bug in that case is calling srand() multiple times, rather
than just once at the beginning. 

You could take a patch to the security or hackers list, but first you
should figure out what problem you are trying to solve. 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44mwapn1pw.fsf>