Created
July 28, 2016 17:54
-
-
Save andrew-qa/032ebb6c3acfbaf290d7a84b9ef5c90a to your computer and use it in GitHub Desktop.
Bash method that returns random binary value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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