EmbLogic's Blog

C Reference function rand() generate a random

number

This function of stdlib will generate a random number.

Usage of rand():

int rand (void);

Parameters:

The function rand() returns a pseudo-random integral number.
This number will be in the range 0 to RAND_MAX. The algorithm of rand() uses a seed to generate the series of numbers, this is why srand must be used to initialize the seed to some distinctive value.

The constant RAND_MAX is defined in standard library (stdlib).

The random numbers are delivered from a predetermined range.

Return value:

Will return an integer value between 0 and RAND_MAX.

as the srand() function used to seed the pseudo generator. the prototype of the srand() is:

void srand(unsigned int seed);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>