totn C Functions

C Language: rand function
(Generate Pseudo-Random Number)

In the C Programming Language, the rand function returns a number between 0 and RAND_MAX.

Syntax

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

int rand(void);

Note

  • Use the srand function to provide a seed value for the rand function. The seed value determines a particular sequence of random numbers to generate when calling the rand function. If a program always uses the same seed value, the rand function will always get the same sequence of numbers from the rand function.
  • If the srand function is not 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: