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 <iostream>
#include <cstdlib>
#include <time.h>
const int LOW = 1;
const int HIGH = 32000;
using namespace std;
int main()
{
int randomNumber;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
for (int i = 0; i < 10; i++)
{
randomNumber = rand() % (HIGH - LOW + 1) + LOW;
cout << randomNumber << " ";
}
cout << "...";
return 0;
}
Output:
$ g++ RandomizedSequenceOfNumbers.cpp $ a.out 312 7423 23444 16008 31816 1823 29315 17424 11753 18384 ...
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 Programming Books
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Check Computer Science Books
- Check C++ Books