Generate random number in c between 1 to 10
- how to use rand in c
- how to use rand in cpp
- how to use rand in calculator
- how to use rand command in ms word
Rand_max in c
Random number in c between 1 and 100...
C library - rand() function
The C stdlib library rand() function is used to returns the pseudo-random number in the range of 0 to RAND_MAX.
RAND_MAX represents the maximum value that can be returned by the rand() function, and their default value may vary depending on the implementation of the c library.
But it is granted to be at least 32767.
Syntax
Following is the C library syntax of the rand() function −
int rand(void)Parameters
This function does not accepts any parameters.
Return Value
This function returns an integer value that is lies between 0 to RAND_MAX.
Example 1
In this example, we create a basic c program to demonstrate the use of rand() function.
#include <stdio.h> #include <stdlib.h> int main() { // store the random value int rand_value = rand(); // display the random value printf("Random Value: %d\n", rand_value); return 0; }Following is the output, −
Random Value: 1804289383Example 2
The below c program used to display the random number within a range using the rand() function.
#include <stdio.h> #include <- how to use rand command in excel
- how to use rand command in matlab