aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--awk.12
-rw-r--r--main.c2
-rw-r--r--run.c8
3 files changed, 7 insertions, 5 deletions
diff --git a/awk.1 b/awk.1
index 057d128..9961910 100644
--- a/awk.1
+++ b/awk.1
@@ -209,7 +209,7 @@ or length of
if no argument.
.TP
.B rand
-random number on (0,1).
+random number on [0,1).
.TP
.B srand
sets seed for
diff --git a/main.c b/main.c
index 92043f4..08af8b5 100644
--- a/main.c
+++ b/main.c
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
/*signal(SIGSEGV, segvcatch); experiment */
srand_seed = 1;
- srand(srand_seed);
+ srandom((unsigned long) srand_seed);
yyin = NULL;
symtab = makesymtab(NSYMTAB/NSYMTAB);
diff --git a/run.c b/run.c
index 9ffad50..7ac6c0b 100644
--- a/run.c
+++ b/run.c
@@ -1579,8 +1579,10 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
}
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 */
@@ -1588,7 +1590,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
else
u = getfval(x);
tmp = u;
- srand((unsigned int) u);
+ srandom((unsigned long) u);
u = srand_seed;
srand_seed = tmp;
break;