aboutsummaryrefslogtreecommitdiff
path: root/bin/rndi
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-09 17:15:40 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-09 17:20:10 +1200
commit9fb350dc7c8cc5259ef24e0cb097031179fab1d6 (patch)
tree839dd0b8ee3f5323b1cd6aefa22b605b99437d62 /bin/rndi
parentMention nosls/sls flags in slsf(1) man page (diff)
downloaddotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.tar.gz
dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.zip
Improve commenting/exit handling in binscripts
Diffstat (limited to 'bin/rndi')
-rwxr-xr-xbin/rndi9
1 files changed, 9 insertions, 0 deletions
diff --git a/bin/rndi b/bin/rndi
index 3dc8689c..bf78951c 100755
--- a/bin/rndi
+++ b/bin/rndi
@@ -2,13 +2,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
}