ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
17 stars 2 forks source link

Deviant "srand" behavior #53

Closed ghost closed 4 years ago

ghost commented 6 years ago

With every commonly used implementation:

Running "srand" gives you the unix timestamp:

$ awk 'BEGIN {srand(); print srand()}'
1527387405

However Mawk 1.3.4 gives something else:

$ mawk 'BEGIN {srand(); printf "%.0f\n", srand()}'
13171862908218520
ThomasDickey commented 6 years ago

It's a configuration option:

https://invisible-island.net/mawk/CHANGES.html#t20140914

        + change default for configure option --enable-init-srand to enable
          this (discussion with Mike Brennan).
        + add -W random option to set initial srand() seed.
...
        + modify initialization of srand default seed from time of day to use
          gettimeofday, etc., so that successive runs of mawk are less likely
          to use the same seed value (suggested by Mike Brennan).

By the way, there's always a patch-date associated with mawk 1.3.4+

ghost commented 4 years ago

I mostly use PHP now as I grew tired of AWK shortcomings. Closing this.