/* File: random2.c

   This file contains the C code that implements
   the functions in the random number library.

   This implementation uses random() instead of rand().
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

/* Global Variables */
int low_range, high_range ;

/* Include the header for the random number library */
#include "random.h"

void SetRandomSeed(void) {
   int time_seed ;

   /* Use the time function to set the seed. */
   time_seed = (int) time(0) ;
   srandom(time_seed) ;
}

void SetRandomRange(int low, int high) {

   low_range = low ;
   high_range = high ;
}

int GetRandomNumber(void) {
   int r ;

   /* Call lrand48() to get a large random number. */
   r = random() ;

   /* Scale the random number within range. */
   r = r % (high_range - low_range + 1) + low_range ;

   return(r) ;
}
