Let us learn how to find and print Random Number in C programming language. This C program makes use of the rand() method to print the random numbers. However, the
However, the srand() method can also be used to find the random numbers.
What is rand() method?
The C rand() function generates a pseudo-random number between 0 and a number defined in a range.
It has its definition in the standard library header file – stdlib.h. Using a modulus operator with the rand() method gives a range to the random integer generation.
num = rand() % 10 indicates the compiler than the random integer should be within 0 and 10, where 10 acts as the RAND_MAX value. This is how you can generate a random number in C programming.
You can even add your own algorithms to improve the random number generation. It may include something like the following:
1 | num = rand() % 10 * 1.5 |
C Program To Find Random Number using Rand() Function
1 2 3 4 5 6 7 8 9 10 | #include<stdio.h> #include<stdlib.h> int main() { int num; num = rand() % 10; printf("Random Integer:\t%d\n", num); return 0; } |
C Program To Generate Random Numbers Between 1 and 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include<stdio.h> #include<stdlib.h> int main() { int count, num; printf("Ten Random Numbers:\t"); for(count = 1; count <= 10; count++) { num = rand() % 100; printf("%d\t", num); } printf("\n"); return 0; } |
Output

If you have any doubts or compilation errors in this C program to generate Random Integers in a given range, let us know about it in the comment section below.
The rand() function is not secure enough in terms of cryptography. You must compile your own algorithm if you want to implement it in the real world systems.
Amazing code for random number generator in C programming.
Which are the other methods for generating random numbers in C programming?
Although there are multiple methods for generating random integers in C programming language, it does not possess good algorithms as such. Here are some of the enlisted:
Abundant knowledge is what I get here at CodingAlpha. The explanation for this random number is just too good.