Possible Duplicate:
Generate Random numbers uniformly over entire range
C++ random float
How can I generate a random number between 5 and 25 in c++ ?
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void main() {
int number;
int randomNum;
srand(time(NULL));
randomNum = rand();
}
In C++11:
Or it could just as well be:
which would give a different distribution on the same range.
Do
rand() % 20
and increment it by 5.The C++ way: