s_and_r.c 372 B

123456789101112131415
  1. /* s_and_r.c -- file for rand1() and srand1() */
  2. /* uses ANSI C portable algorithm */
  3. static unsigned long int next = 1; /* the seed */
  4. int rand1(void)
  5. {
  6. /* magic formula to generate pseudorandom number */
  7. next = next * 1103515245 + 12345;
  8. return (unsigned int) (next/65536) % 32768;
  9. }
  10. void srand1(unsigned int seed)
  11. {
  12. next = seed;
  13. }