aboutsummaryrefslogtreecommitdiff
path: root/bin/rnda.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/rnda.sh')
-rw-r--r--bin/rnda.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/bin/rnda.sh b/bin/rnda.sh
new file mode 100644
index 00000000..b09a8b6f
--- /dev/null
+++ b/bin/rnda.sh
@@ -0,0 +1,19 @@
+# Choose a random argument using rndi(1df)
+
+# Check we have at least one argument
+if [ "$#" -eq 0 ] ; then
+ printf >&2 'rnda: No args given\n'
+ exit 2
+fi
+
+# Get a random seed from rnds(1df); if it's empty, that's still workable
+seed=$(rnds)
+
+# Get a random integet from 1 to the number of arguments
+argi=$(rndi 1 "$#" "$seed") || exit
+
+# Shift until that argument is the first argument
+shift "$((argi-1))"
+
+# Print it
+printf '%s\n' "$1"