Created
April 2, 2013 15:41
-
-
Save bancek/5293221 to your computer and use it in GitHub Desktop.
Bash random
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
rseed=42 | |
random=0 | |
function generate_random { | |
if [[ $rseed == 0 ]]; then | |
rseed=123459876 | |
fi | |
h=$(($rseed / 127773)) | |
l=$(($rseed % 127773)) | |
rseed=$((16807 * $l - 2836 * $h)) | |
if [[ $rseed < 0 ]]; then | |
rseed=$(($rseed + 0x7fffffff)) | |
fi | |
random=$(($rseed & 32767)) | |
} | |
generate_random | |
echo $random | |
generate_random | |
echo $random |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment