// random.cpp - simple example of setting random number seeds with time #include using namespace std; double rnd(double a, double b) { return ((double)rand() / RAND_MAX) * (b - a) + a; // return random number from [a, b) } int main() { srand(time(nullptr)); // use time in seconds to set seed cout << "5 int random numbers from [0, RAND_MAX]:" << endl; for (int i = 0; i < 5; ++i) cout << rand() << " "; cout << endl; cout << endl; cout << "5 int random numbers from [0, 100):" << endl; for (int i = 0; i < 5; ++i) cout << rand() % 100 << " "; cout << endl; cout << endl; cout << "5 double random numbers from [0, 1):" << endl; for (int i = 0; i < 5; ++i) cout << rnd(0., 1.) << " "; cout << endl; cout << endl; cout << "5 double random numbers from [-10, 10):" << endl; for (int i = 0; i < 5; ++i) cout << rnd(-10., 10.) << " "; cout << endl; cout << endl; return 0; }