Created
March 27, 2013 06:31
-
-
Save tai2/5252186 to your computer and use it in GitHub Desktop.
Linear congruential generator
c.f. http://en.wikipedia.org/wiki/Linear_congruential_generator
This file contains hidden or 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
| #include <stdio.h> | |
| int lcg() { | |
| static int seed = 8; | |
| seed = (1664525 * seed + 1013904223) & 2147483647; | |
| return seed; | |
| } | |
| int | |
| main() { | |
| int i; | |
| for (i = 0; i < 300; i++) { | |
| printf("%d ", lcg()); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment