Last active
August 29, 2015 14:05
-
-
Save horus/03c3d7c17703536033c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: awk.1 | |
=================================================================== | |
--- awk.1 (revision 270781) | |
+++ awk.1 (working copy) | |
@@ -208,7 +208,7 @@ | |
if no argument. | |
.TP | |
.B rand | |
-random number on (0,1) | |
+random number on [0,1) | |
.TP | |
.B srand | |
sets seed for | |
Index: main.c | |
=================================================================== | |
--- main.c (revision 270781) | |
+++ main.c (working copy) | |
@@ -74,7 +74,7 @@ | |
signal(SIGFPE, fpecatch); | |
srand_seed = 1; | |
- srand(srand_seed); | |
+ srandom((unsigned long) srand_seed); | |
yyin = NULL; | |
symtab = makesymtab(NSYMTAB/NSYMTAB); | |
Index: run.c | |
=================================================================== | |
--- run.c (revision 270781) | |
+++ run.c (working copy) | |
@@ -1521,8 +1521,10 @@ | |
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 @@ | |
else | |
u = getfval(x); | |
tmp = u; | |
- srand((unsigned int) u); | |
+ srandom((unsigned long) u); | |
u = srand_seed; | |
srand_seed = tmp; | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment