Skip to content

Instantly share code, notes, and snippets.

@andrew-qa
Created July 28, 2016 17:54
Show Gist options
  • Save andrew-qa/032ebb6c3acfbaf290d7a84b9ef5c90a to your computer and use it in GitHub Desktop.
Save andrew-qa/032ebb6c3acfbaf290d7a84b9ef5c90a to your computer and use it in GitHub Desktop.
Bash method that returns random binary value
function result()
{
BINARY=2
T=1
number=$RANDOM
let "number %= $BINARY"
# Note that let "number >>= 14" gives a better random distribution
#+ (right shifts out everything except last binary digit).
if [ "$number" -eq $T ]
then
return 1
else
return 0
fi
}
result
echo $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment