aboutsummaryrefslogtreecommitdiff
path: root/bin/myb
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-03 16:27:47 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-03 16:28:24 +1200
commit7b2392c4ad351986617c4b474bad6a3d9cd30627 (patch)
tree44428b57bb257f604d2e022b55759d27b5374899 /bin/myb
parentRemove unneeded quoting in tlcs(1) (diff)
downloaddotfiles-7b2392c4ad351986617c4b474bad6a3d9cd30627.tar.gz
dotfiles-7b2392c4ad351986617c4b474bad6a3d9cd30627.zip
Change maybe(1) to POSIX sh, rename myb(1)
Diffstat (limited to 'bin/myb')
-rwxr-xr-xbin/myb22
1 files changed, 22 insertions, 0 deletions
diff --git a/bin/myb b/bin/myb
new file mode 100755
index 00000000..57a37ad5
--- /dev/null
+++ b/bin/myb
@@ -0,0 +1,22 @@
+#!/bin/sh
+# Exit with success or failure with a given probability
+self=myb
+
+# No more than one argument
+if [ "$#" -gt 1 ] ; then
+ printf >&2 '%s: Unexpected arguments\n' "$self"
+ exit 2
+fi
+
+# Sole accepted argument is denominator of the probability fraction, e.g. 3 is
+# a probability of 1/3; defaults to 2
+denom=${1:-2}
+
+# Denominator must be positive integer (it can be one)
+if [ "$((denom > 0))" -ne 1 ] ; then
+ printf >&2 '%s: Illegal denominator %s\n' "$self" "$denom"
+ exit 2
+fi
+
+# Perform the test; that's our exit value
+test "$(rndi 1 "$denom")" -eq 1