The rand() function in C generates pseudo-random numbers in a set sequence that repeats each time the program is run. It returns an integer between 0 and RAND_MAX, a constant that is at least 32767. A program using rand() in a loop to generate 5 random numbers will output the same sequence of numbers each time the code is compiled and executed.
The rand() function in C generates pseudo-random numbers in a set sequence that repeats each time the program is run. It returns an integer between 0 and RAND_MAX, a constant that is at least 32767. A program using rand() in a loop to generate 5 random numbers will output the same sequence of numbers each time the code is compiled and executed.
rand() function is used in C to generate random numbers. If we generate a sequence of
random number with rand() function, it will create the same sequence again and again every time program runs. Say if we are generating 5 random numbers in C with the help of rand() in a loop, then every time we compile and run the program our output must be the same sequence of numbers. Syntax: int rand(void): returns a pseudo-random number in the range of 0 to RAND_MAX. RAND_MAX: is a constant whose default value may vary between implementations but it is granted to be at least 32767.
// C program to generate random numbers
#include <stdio.h> #include <stdlib.h>
// Driver program int main(void) { // This program will create same sequence of // random numbers on every program run