Created
April 6, 2012 05:48
-
-
Save dbrady/2317393 to your computer and use it in GitHub Desktop.
Rand using bc
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
#!/bin/sh | |
# Linear Congruential Generator using bc | |
# | |
# Note the shenanigans necessary to seed the generator with the epoch | |
# time: $(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s") does nothing | |
# more than return the current date in epoch seconds, which we use to | |
# seed the generator. This generator is due to Knuth, and cited in | |
# Numerical Recipes in C, chapter 7. It's fast on old 32-bit machines | |
# but not a very good RNG: | |
echo "(1664525*($(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s")%2^32)+1013904223)%2^32" | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment