/*********************************************************
 * From C PROGRAMMING: A MODERN APPROACH, Second Edition *
 * By K. N. King                                         *
 * Copyright (c) 2008, 1996 W. W. Norton & Company, Inc. *
 * All rights reserved.                                  *
 * This program may be freely distributed for class use, *
 * provided that this copyright notice is retained.      *
 *********************************************************/
/* trand.c (Chapter 26, page 687) */
/* Tests the pseudo-random sequence generation functions */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  int i, seed;
  printf("This program displays the first five values of "
         "rand.\n");
  for (;;) {
    for (i = 0; i < 5; i++)
      printf("%d ", rand());
    printf("\n\n");
    printf("Enter new seed value (0 to terminate): ");
    scanf("%d", &seed);
    if (seed == 0)
      break;
    srand(seed);
  }
  return 0;
}