This is a C Program to generate random numbers within given range. This version of code uses rand() and srand() functions.
Here is source code of the C Program to Generate Randomized Sequence of Given Range of Numbers. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int LOW = 1;
const int HIGH = 32000;
int main() {
int randomNumber, i;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
for (i = 0; i < 10; i++) {
randomNumber = rand() % (HIGH - LOW + 1) + LOW;
printf("%d ", randomNumber);
}
printf("...");
return 0;
}
Output:
$ gcc RandomizedSeqOfNumbers.cpp $ ./a.out 24874 17738 3972 19634 646 5665 1147 9374 3726 3556 ...
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Computer Science MCQs
- Practice BCA MCQs
- Buy C Books
- Apply for Computer Science Internship
- Buy Computer Science Books