Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long int rand_next = 1;
- /*
- * int rand()
- * Taken from the K&R C programming language book. Page 46.
- * returns a pseudo-random integer of 0..32767. Note that
- * this is compatible with the System V function rand(), not
- * with the bsd function rand() that returns 0..(2**31)-1.
- */
- int rand ()
- {
- rand_next = rand_next * 1103515245 + 12345;
- return ((unsigned int)(rand_next / 65536) % 32768);
- }
- /*
- * srand(seed)
- * companion routine to rand(). Initializes the seed.
- */
- void srand(unsigned int seed)
- {
- rand_next = seed;
- }
Add Comment
Please, Sign In to add comment