hi,
commit 1edd2abb changed awk(1) so that srand() called without a seed
triggers the use of arc4random(3) for subsequent rand() calls
(unfortunately, this feature is not documented).
however, awk has historically assumed $0 for builtin functions called
without an explicit argument:
# echo 256 | awk '{ print sqrt }'
16
echo foo bar | awk '{ print toupper }'
FOO BAR
this is in contrast with srand()'s "new" (since 2004) behaviour:
# echo "" | awk '{ srand(1); print rand }'
0.840188
# echo 1 | awk '{ srand; print rand }'
0.393267
# echo 1 | awk '{ srand($0); print rand }'
0.436186
note that srand() will only ignore its argument if it is $0; for n > 0,
srand($n) works as intended:
# echo 0 1 | awk '{ srand($1); print rand }'
0.840188
do we want to keep this behaviour, or should we revert 1edd2abb? while i
like the idea of allowing the use of arc4random(), i treasure semantic
congruence in a programming language, so i'm inclined towards the latter
option. thoughts?
-p.
[addendum:
there's also the fact that srand() is supposed to return the last seed
used. srand() (w/o arguments) currently returns garbage (that is
undoubtedly a bug):
# echo 1 | awk '{ print srand }'
4.22615e-317
# echo 1 | awk '{ srand(1); print srand; srand(1); print srand(2) }'
2.122e-314
1
but assuming srand() switches to arc4random(), what should a subsequent
srand(x) call return?]