How to generate a random number in a given range in C.
Input : Lower = 50, Upper = 100, Count of random Number = 5 Output : 91 34 21 88 29 Explanation: lower is the lower limit of the range and upper is the upper limit of the range. Output contains 5 random numbers in given range.
As C does not have an inbuilt function for generating a number in the range, but it does have rand function which generate a random number from 0 to RAND_MAX. With the help of rand () a number in range can be generated as num = (rand() % (upper – lower + 1)) + lower
Note : Output generated on each run may be different because number is generated randomly.
- Generating Random String Using PHP
- Generating random Id's in Python
- Generating Random id's using UUID in Python
- Generating random numbers in Java
- Generating random strings until a given string is generated
- Erdos Renyl Model (for generating Random Graphs)
- Test Case Generation | Set 5 (Generating random Sorted Arrays and Palindromes)
- Python | Generate random numbers within a given range and store in a list
- Random vs Secure Random numbers in Java
- C++ program to generate random number
- Pseudo Random Number Generator (PRNG)
- Select a random number from stream, with O(1) space
- Project Idea | ( True Random Number Generator)
- Python implementation of automatic Tic Tac Toe game using random number
- Test Case Generation | Set 2 ( Random Characters, Strings and Arrays of Random Strings)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.