From owner-svn-src-stable@FreeBSD.ORG Fri Oct 10 23:19:35 2014 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C000E75C; Fri, 10 Oct 2014 23:19:35 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 91BB27D; Fri, 10 Oct 2014 23:19:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9ANJZ5E063340; Fri, 10 Oct 2014 23:19:35 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9ANJYqt063337; Fri, 10 Oct 2014 23:19:34 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201410102319.s9ANJYqt063337@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Fri, 10 Oct 2014 23:19:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r272919 - stable/9/contrib/one-true-awk X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2014 23:19:35 -0000 Author: pfg Date: Fri Oct 10 23:19:34 2014 New Revision: 272919 URL: https://svnweb.freebsd.org/changeset/base/272919 Log: MFC r271879: awk: Use random(3) instead of rand(3) While none of them is considered even near to cryptographic level, random(3) is a better random generator than rand(3). Use random(3) for awk as is done in other systems. PR: 193147 Modified: stable/9/contrib/one-true-awk/awk.1 stable/9/contrib/one-true-awk/main.c stable/9/contrib/one-true-awk/run.c Directory Properties: stable/9/contrib/one-true-awk/ (props changed) Modified: stable/9/contrib/one-true-awk/awk.1 ============================================================================== --- stable/9/contrib/one-true-awk/awk.1 Fri Oct 10 23:18:44 2014 (r272918) +++ stable/9/contrib/one-true-awk/awk.1 Fri Oct 10 23:19:34 2014 (r272919) @@ -208,7 +208,7 @@ or of if no argument. .TP .B rand -random number on (0,1) +random number on [0,1) .TP .B srand sets seed for Modified: stable/9/contrib/one-true-awk/main.c ============================================================================== --- stable/9/contrib/one-true-awk/main.c Fri Oct 10 23:18:44 2014 (r272918) +++ stable/9/contrib/one-true-awk/main.c Fri Oct 10 23:19:34 2014 (r272919) @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) signal(SIGFPE, fpecatch); srand_seed = 1; - srand(srand_seed); + srandom((unsigned long) srand_seed); yyin = NULL; symtab = makesymtab(NSYMTAB/NSYMTAB); Modified: stable/9/contrib/one-true-awk/run.c ============================================================================== --- stable/9/contrib/one-true-awk/run.c Fri Oct 10 23:18:44 2014 (r272918) +++ stable/9/contrib/one-true-awk/run.c Fri Oct 10 23:19:34 2014 (r272919) @@ -1521,8 +1521,10 @@ Cell *bltin(Node **a, int n) /* builtin u = (Awkfloat) system(getsval(x)) / 256; /* 256 is unix-dep */ break; case FRAND: - /* in principle, rand() returns something in 0..RAND_MAX */ - u = (Awkfloat) (rand() % RAND_MAX) / RAND_MAX; + /* random() returns numbers in [0..2^31-1] + * in order to get a number in [0, 1), divide it by 2^31 + */ + u = (Awkfloat) random() / (0x7fffffffL + 0x1UL); break; case FSRAND: if (isrec(x)) /* no argument provided */ @@ -1530,7 +1532,7 @@ Cell *bltin(Node **a, int n) /* builtin else u = getfval(x); tmp = u; - srand((unsigned int) u); + srandom((unsigned long) u); u = srand_seed; srand_seed = tmp; break;