r_drive1.c 571 B

123456789101112131415161718192021222324
  1. /* r_drive1.c -- test rand1() and srand1() */
  2. /* compile with s_and_r.c */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. extern void srand1(unsigned int x);
  6. extern int rand1(void);
  7. int main(void)
  8. {
  9. int count;
  10. unsigned seed;
  11. printf("Please enter your choice for seed.\n");
  12. while (scanf("%u", &seed) == 1)
  13. {
  14. srand1(seed); /* reset seed */
  15. for (count = 0; count < 5; count++)
  16. printf("%d\n", rand1());
  17. printf("Please enter next seed (q to quit):\n");
  18. }
  19. printf("Done\n");
  20. return 0;
  21. }