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.
Related Posts:
- Check C Books
- Apply for C Internship
- Practice BCA MCQs
- Check Computer Science Books
- Practice Computer Science MCQs