Date: Fri, 10 Oct 2014 23:18:45 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r272918 - stable/10/contrib/one-true-awk Message-ID: <201410102318.s9ANIjps063160@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Fri Oct 10 23:18:44 2014 New Revision: 272918 URL: https://svnweb.freebsd.org/changeset/base/272918 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/10/contrib/one-true-awk/awk.1 stable/10/contrib/one-true-awk/main.c stable/10/contrib/one-true-awk/run.c Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/one-true-awk/awk.1 ============================================================================== --- stable/10/contrib/one-true-awk/awk.1 Fri Oct 10 22:18:09 2014 (r272917) +++ stable/10/contrib/one-true-awk/awk.1 Fri Oct 10 23:18:44 2014 (r272918) @@ -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/10/contrib/one-true-awk/main.c ============================================================================== --- stable/10/contrib/one-true-awk/main.c Fri Oct 10 22:18:09 2014 (r272917) +++ stable/10/contrib/one-true-awk/main.c Fri Oct 10 23:18:44 2014 (r272918) @@ -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/10/contrib/one-true-awk/run.c ============================================================================== --- stable/10/contrib/one-true-awk/run.c Fri Oct 10 22:18:09 2014 (r272917) +++ stable/10/contrib/one-true-awk/run.c Fri Oct 10 23:18:44 2014 (r272918) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410102318.s9ANIjps063160>