Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I am well aware that this code is not good (no static, not considering overflows on some machines) and is not optimal (not using & for fast modulus). I'm just trying to make my code as clear and simple as possible.
- #include <stdio.h>
- #define RAND_MAX 2048
- int rseed = 0; // Global variable: course standards wants to know your location
- void srand(int);
- int rand();
- int main()
- {
- int i;
- srand(1000);
- for (i = 0; i < 100; i++)
- {
- printf("%d\n", rand());
- }
- return 0;
- }
- void srand(int seed)
- {
- rseed = seed;
- }
- int rand()
- {
- rseed = (rseed * 69420 + 21) % (RAND_MAX + 1);
- return rseed;
- }
Advertisement
Add Comment
Please, Sign In to add comment