diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-03 23:48:08 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-03 23:50:20 +1200 |
commit | a6ea6531fd1dee294b5fc1251adc143a0cc73357 (patch) | |
tree | 8356ee61d97cd3e5d777283f974ebac328dd2bc8 /games | |
parent | Tweaks to rndn(6) seed definition (diff) | |
download | dotfiles-a6ea6531fd1dee294b5fc1251adc143a0cc73357.tar.gz dotfiles-a6ea6531fd1dee294b5fc1251adc143a0cc73357.zip |
Add seed validation to rndn(8)
Diffstat (limited to 'games')
-rwxr-xr-x | games/rndn | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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 |