aboutsummaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-03 23:48:08 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-03 23:50:20 +1200
commita6ea6531fd1dee294b5fc1251adc143a0cc73357 (patch)
tree8356ee61d97cd3e5d777283f974ebac328dd2bc8 /games
parentTweaks to rndn(6) seed definition (diff)
downloaddotfiles-a6ea6531fd1dee294b5fc1251adc143a0cc73357.tar.gz
dotfiles-a6ea6531fd1dee294b5fc1251adc143a0cc73357.zip
Add seed validation to rndn(8)
Diffstat (limited to 'games')
-rwxr-xr-xgames/rndn8
1 files changed, 7 insertions, 1 deletions
diff --git a/games/rndn b/games/rndn
index ecc374b1..ebbee9f6 100755
--- a/games/rndn
+++ b/games/rndn
@@ -34,7 +34,13 @@ done
shift "$((OPTIND-1))"
# If no seed given, get one from Bash's $RANDOM
-: "${seed:=$RANDOM}" ** 2
+: "${seed:=$((RANDOM ** 2))}"
+
+# Check seed meets algorithm conditions
+if [[ $seed == *[^0-9]* ]] || ((seed < 0)) ; then
+ printf >&2 '%s: error: seed must be non-negative integer\n' "$self"
+ exit 2
+fi
# Apply algorithm
for ((seed += 10, i = 0; i < ${#seed}; i++)) ; do