aboutsummaryrefslogtreecommitdiff
path: root/bin/rnds
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/rnds
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/rnds')
-rwxr-xr-xbin/rnds15
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/rnds b/bin/rnds
index 98851208..c5ffabe4 100755
--- a/bin/rnds
+++ b/bin/rnds
@@ -1,11 +1,22 @@
#!/bin/sh
# Try to get a low-quality random seed from a random device if possible
-[ "$#" -le 1 ] || exit 2
+
+# Sole optional argument is the bytes to read; 32 is the default
+count=${1:-32}
+
+# Try and find a random device to use; none of these are specified by POSIX
for dev in /dev/urandom /dev/arandom /dev/random '' ; do
[ -e "$dev" ] && break
done
+
+# Bail if we couldn't find a random device
[ -n "$dev" ] || exit 1
-count=${1:-32}
+
+# Read the bytes from the device
dd if="$dev" bs=1 count="$count" 2>/dev/null |
+
+# Run cksum(1) over the read random bytes
cksum |
+
+# cut(1) the cksum(1) output to only the first field, and print that to stdout
cut -d' ' -f1