diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-07-03 12:35:14 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-07-03 12:35:14 +1200 |
commit | 64427872e9a259dab9e2b27dd6e3e1f430c06274 (patch) | |
tree | 7746d50d6f837c1bdb1480b72bd84db0d663451f | |
parent | More corrections to rndi(1df) man page (diff) | |
download | dotfiles-64427872e9a259dab9e2b27dd6e3e1f430c06274.tar.gz dotfiles-64427872e9a259dab9e2b27dd6e3e1f430c06274.zip |
Work around mawk's srand() behaviour
Specific values for these tasks get chosen way more often than other in
mawk, and it seems to be caused by the random seed being above a certain
value. Not sure if it's a bug or how it interacts with the POSIX
standard, but this seems to fix it.
-rw-r--r-- | bin/rndi.awk | 5 | ||||
-rw-r--r-- | bin/rndl.awk | 5 | ||||
-rw-r--r-- | games/pks.awk | 5 |
3 files changed, 12 insertions, 3 deletions
diff --git a/bin/rndi.awk b/bin/rndi.awk index 07c69bc7..7d5a5b96 100644 --- a/bin/rndi.awk +++ b/bin/rndi.awk @@ -16,10 +16,13 @@ BEGIN { if (lower >= upper) fail("Bounds must be numeric, first lower than second") - # Seed the random number generator + # Get a random seed if rnds(1df) available rnds = "rnds 2>/dev/null" rnds | getline seed close(rnds) + + # Truncate the seed to 8 characters because mawk might choke on it + seed = substr(seed,1,8) if (length(seed)) srand(seed + 0) else diff --git a/bin/rndl.awk b/bin/rndl.awk index 925235ee..99f5b4e1 100644 --- a/bin/rndl.awk +++ b/bin/rndl.awk @@ -6,10 +6,13 @@ BEGIN { # Name self self = "rndl" - # Seed the random number generator + # Get a random seed if rnds(1df) available rnds = "rnds 2>/dev/null" rnds | getline seed close(rnds) + + # Truncate the seed to 8 characters because mawk might choke on it + seed = substr(seed,1,8) if (length(seed)) srand(seed + 0) else diff --git a/games/pks.awk b/games/pks.awk index b71d2dc4..1a441980 100644 --- a/games/pks.awk +++ b/games/pks.awk @@ -12,10 +12,13 @@ BEGIN { ARGV[1] = "/usr/share/dict/words" } - # Seed the random number generator + # Get a random seed if rnds(1df) available rnds = "rnds 2>/dev/null" rnds | getline seed close(rnds) + + # Truncate the seed to 8 characters because mawk might choke on it + seed = substr(seed,1,8) if (length(seed)) srand(seed + 0) else |