/* File: random_numbers.cpp
 *
 * Produce a variety of random number distributions.
 */

extern "C" {               /* the random functions are only defined in C  */
    #include <stdlib.h>    /*   so we must link in the C library          */
    #include <time.h>              
    #include <limits.h>

    long random();
    void srandom(unsigned int);
}

#include "random_numbers.h"

/*
 * initialize_random() - initialize the random number generator so that each
 *     run of the simulator receives a different stream of numbers.
 */
void initialize_random()
{
    srandom(time(0));
}

/*
 * get_discrete_random() - return a random number between 0 and limit-1
 */
int get_discrete_random(int limit)
{
    int x = random();
    return (x % limit);     // % is not usually a good idea, but ok for our case
}

/*
 * get_cont_random() - return a uniform "continuous" random number in the
 *                     open interval [0, limit)
 */
double get_cont_random(double limit)
{
    int x = random();
    return (((double)x / (double)LONG_MAX) * limit);
}


