diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-16 19:54:57 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-16 19:57:58 +1200 |
commit | 481f4fa397bbdadcba7d7e6f93f3e058268a95b2 (patch) | |
tree | 7c01924feb4f58c038c9f05dabea00f85314116b /bin/rndi.awk | |
parent | Remove .m4 from suffixes (diff) | |
download | dotfiles-481f4fa397bbdadcba7d7e6f93f3e058268a95b2.tar.gz dotfiles-481f4fa397bbdadcba7d7e6f93f3e058268a95b2.zip |
Move awk scripts into shb(1)
Diffstat (limited to 'bin/rndi.awk')
-rw-r--r-- | bin/rndi.awk | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bin/rndi.awk b/bin/rndi.awk new file mode 100644 index 00000000..337498cb --- /dev/null +++ b/bin/rndi.awk @@ -0,0 +1,22 @@ +# Get a low-quality random number between two integers. Depending on the awk +# implementation, if you don't provide a third argument (a seed), you might get +# very predictable random numbers based on the current epoch second. + +BEGIN { + + # Seed with the third argument if given + if (ARGV[3]) { + srand(ARGV[3]) + } + + # If not, just seed with what is probably a date/time-derived value + else { + srand() + } + + # Print a random integer bounded by the first and second arguments + print int(ARGV[1]+rand()*(ARGV[2]-ARGV[1]+1)) + + # Bail before processing any lines + exit +} |