Guest User

Untitled

a guest
May 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. unsigned long int rand_next = 1;
  2.  
  3. /*
  4. * int rand()
  5. * Taken from the K&R C programming language book. Page 46.
  6. * returns a pseudo-random integer of 0..32767. Note that
  7. * this is compatible with the System V function rand(), not
  8. * with the bsd function rand() that returns 0..(2**31)-1.
  9. */
  10. int rand ()
  11. {
  12. rand_next = rand_next * 1103515245 + 12345;
  13. return ((unsigned int)(rand_next / 65536) % 32768);
  14. }
  15.  
  16. /*
  17. * srand(seed)
  18. * companion routine to rand(). Initializes the seed.
  19. */
  20. void srand(unsigned int seed)
  21. {
  22. rand_next = seed;
  23. }
Add Comment
Please, Sign In to add comment