Random number function
File for random.h
#include "random.h"
/*****************************************************
* *
* File Name: random.h *
* Author: Brenda Sonderegger *
* Contents: *
* get_random() *
* *
*****************************************************/
/*****************************************************
* int get_random(int low, int high) *
* Author: Brenda Sonderegger *
* Last Modified: Sept. 23, 1998 *
* Parameters: two integers *
* Return value: random integer between low and high *
* Side Effect: none *
* Description: guarantees that the returned value is *
* between low and high inclusively *
* Functions called: from stdlib.h *
* srand() *
* rand() *
* from time.h *
* time() *
* *
*****************************************************/
int get_random(int low, int high);
File for random.c
#include "random.h"
/*****************************************************
* *
* File Name: random.c *
* Author: Brenda Sonderegger (all functions) *
* Contents: *
* get_random() *
* *
*****************************************************/
/*****************************************************
* int get_random(int low, int high) *
* Author: Brenda Sonderegger *
* Last Modified: Sept. 23, 1998 *
* Parameters: two integers *
* Return value: random integer between low and high *
* Side Effect: none *
* Description: guarantees that the returned value is *
* between low and high inclusively *
* Functions called: from stdlib.h *
* srand() *
* rand() *
* from time.h *
* time() *
* *
*****************************************************/
int get_random(int low, int high)
{
static int seeded = 0;
int random;
if (seeded == 0)
{
srand((unsigned)time((time_t *) NULL));
seeded = 1;
}
random = rand() % (high - low + 1) + low;
return (random);
}