rand function(Generate Pseudo-Random Number) in C Language – example and detail

In the C Programming Language, the rand characteristic returns a wide variety between 0 and RAND_MAX.

Syntax

The syntax for the rand characteristic in the C Language is:

int rand(void);

Note Use the srand characteristic to grant a seed value for the rand function. The seed cost determines a particular sequence of random numbers to generate when calling the rand function. If a application always uses the equal seed value, the rand function will usually get the equal sequence of numbers from the rand function. If the srand feature is no longer used to provide a seed value, the seed value is assumed to be 1.

Returns

The rand function returns a number between 0 and RAND_MAX (inclusive).

Required Header

In the C Language, the required header for the rand function is:

#include <stdlib.h>

Applies To

In the C Language, the rand function can be used in the following versions:

ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the rand function:

srand function <stdlib.h>