Skip to content

Instantly share code, notes, and snippets.

@cjp
Created December 11, 2014 17:04
Show Gist options
  • Save cjp/aca09e512fc43b6d7109 to your computer and use it in GitHub Desktop.
Save cjp/aca09e512fc43b6d7109 to your computer and use it in GitHub Desktop.
Shell script that rolls a single die
#!/bin/sh
random() {
od -A n -t d -N 1 /dev/random | tr '\n' ' ' | awk '{print $1}'
}
rolldie() {
local r=$(random)
while [ $r -gt 6 -o $r -lt 1 ]; do
r=$(random)
done
echo $r
}
rolldie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment