diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-07-01 21:49:27 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-07-01 22:00:07 +1200 |
commit | 7adef2006aaff89db93c87fd1470a688fb1d4907 (patch) | |
tree | 25e967034dad315ca11b50b51b2d1088c65eaf00 /games | |
parent | Better implementation of pks(6df) (diff) | |
download | dotfiles-7adef2006aaff89db93c87fd1470a688fb1d4907.tar.gz dotfiles-7adef2006aaff89db93c87fd1470a688fb1d4907.zip |
Reimplement rndl(1df) in Awk
Removes the need for the temporary file. Also refactor pks(6df) to
accommodate it.
Diffstat (limited to 'games')
-rw-r--r-- | games/pks.awk | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/games/pks.awk b/games/pks.awk index c490e8dc..c7ff320d 100644 --- a/games/pks.awk +++ b/games/pks.awk @@ -13,12 +13,13 @@ BEGIN { } # Seed the random number generator - srand() + "rnds 2>/dev/null" | getline seed + srand(seed) } # Iterate over the lines, randomly assigning the first field of each one with a # decreasing probability; this method -rand() * NR < 1 { wr = $1 } +$1 ~ /[[:alpha:]]/ && rand() * ++n < 1 { wr = $1 } # Ha, ha, ha! Incompetent! END { @@ -27,11 +28,10 @@ END { if (!NR) exit 1 - # Strip trailing possessives - sub(/'s*$/, "", wr) + # Strip trailing possessives and punctuation + sub(/[^[:alpha:]]+s*$/, "", wr) # Two or three "has"? Important decisions here folks - srand() hr = int(rand()*2+1) for (ha = "Ha"; hi < hr; hi++) ha = ha ", ha" |