rand(3) CLIX rand(3)
NAME
rand, srand - Simple random-number generator
LIBRARY
Standard Math Library (libc.a)
SYNOPSIS
int rand(
void );
void srand(
unsigned seed );
PARAMETERS
seed An unsigned integer used to initialize the pseudo-random number
generator.
DESCRIPTION
The rand() function uses a multiplicative congruential random-number
generator with period 2^32 that returns successive pseudo-random numbers
in the range from 0 to (2^15)-1.
The srand() function can be called at any time to reset the random-number
generator to a given starting point. The generator is initially seeded
with a value of 1.
EXAMPLES
To do fill an array with random integers:
int index;
int array[100];
srand(23); /*Set the generator.*/
for(index = 0; index < 100; ++index)
array[index] = rand();
NOTES
The spectral properties of rand() are limited. The drand48() function
provides a much better, though more elaborate, random-number generator.
To compile a program with this function, use the -lm flag to the cc
command to include the libm.a library.
RETURN VALUES
2/94 - Intergraph Corporation 1
rand(3) CLIX rand(3)
The rand() function returns a random number between 0 and (2^15)-1. The
function srand() does not return a value.
RELATED INFORMATION
Functions: drand48(3)
2 Intergraph Corporation - 2/94