From owner-freebsd-questions@FreeBSD.ORG Wed Aug 27 19:59:15 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A770F2FF for ; Wed, 27 Aug 2014 19:59:15 +0000 (UTC) Received: from be-well.ilk.org (be-well.ilk.org [23.30.133.173]) by mx1.freebsd.org (Postfix) with ESMTP id 7E5383256 for ; Wed, 27 Aug 2014 19:59:15 +0000 (UTC) Received: from lowell-desk.lan (lowell-desk.lan [172.30.250.41]) by be-well.ilk.org (Postfix) with ESMTP id 384EB33C1E; Wed, 27 Aug 2014 15:59:09 -0400 (EDT) Received: by lowell-desk.lan (Postfix, from userid 1147) id 30AAE39860; Wed, 27 Aug 2014 15:59:07 -0400 (EDT) From: Lowell Gilbert To: Chenguang Li Subject: Re: Ask for opinion: changing rand(3) to random(3) in awk(1) References: Reply-To: freebsd-questions@freebsd.org Date: Wed, 27 Aug 2014 15:59:07 -0400 In-Reply-To: (Chenguang Li's message of "Wed, 27 Aug 2014 15:30:56 +0800") Message-ID: <44mwapn1pw.fsf@lowell-desk.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Aug 2014 19:59:15 -0000 Chenguang Li 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.