hi natano,

diff --git a/usr.bin/awk/awk.1 b/usr.bin/awk/awk.1
index 514f989..e1c8ccc 100644
--- a/usr.bin/awk/awk.1
+++ b/usr.bin/awk/awk.1
@@ -487,7 +487,7 @@ to
and returns the previous seed.
If
.Fa expr
-is omitted, the time of day is used instead.
+is omitted, the random number generator is seeded in a system dependant manner.
.El
.Ss String Functions
.Bl -tag -width "split(s, a, fs)"

that's not exactly true, since no generator is seeded; srand() is
bypassed completely and arc4random(3) is used _instead_. in that light,
i think something like this would be better:

If
.Fa expr
is omitted,
.Xr arc4random 3
is used to generate random numbers in subsequent
.Fn rand
calls.

i can't provide a full diff right now, sorry :(

Meh. The current solution seems to have been good enough to survive for
a whole decade - also, I think using arc4random() is a good thing (TM).
The use case where the values produced are predictable (when srand() is
called with an argument) continues to be.

what i find hard to live with is that, for $0 = 9 (for instance) and $1
= 9, srand($0) behaves differently than srand($1)... but i won't push my
personal views on anyone. ;) if you think that's the best, i'm fine with
leaving things as they are.

diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c
index 9bb85fd..b798da5 100644
--- a/usr.bin/awk/run.c
+++ b/usr.bin/awk/run.c
@@ -1588,9 +1588,10 @@ Cell *bltin(Node **a, int n)     /* builtin functions. 
a[0] is type, a[1] is arg lis
                        u = (Awkfloat)arc4random() / 0xffffffff;
                break;
        case FSRAND:
-               if (isrec(x))   /* no argument provided, want arc4random() */
+               if (isrec(x)) { /* no argument provided, want arc4random() */
                        use_srandom = 0;
-               else {
+                       u = srand_seed;
+               } else {
                        use_srandom = 1;
                        u = getfval(x);
                        tmp = u;

i had the exact same diff in my tree; ok pedro@.

cheers,

-p.

Reply via email to