#include <stdio.h>
#include <stdlib.h>
#include <time.h>	/* time() */
#include <sys/time.h>	/* gettimeofday() */

int irand_r(unsigned int *seedp, int lb, int ub)
{
  return lb + (int)((double)(ub - lb + 1)*rand_r(seedp)/(RAND_MAX+1.0));
}
int main(void)
{
  int i;
  unsigned seed;
#if defined(UNSAFE)

  time((time_t *)&seed);
#else
  struct timeval tm;

  gettimeofday(&tm, NULL);
  seed = (unsigned)(tm.tv_sec+tm.tv_usec);
#endif
  for (i=0; i<10; i++)
    printf("%d\n", irand_r(&seed, 0, 9));
  return 0;
}
