// random.cpp - simple example of setting random number seeds with time #include using namespace std; double rnd(double a, double b) { return (b - a)* drand48() + a; // return random number from [a, b) } int main() { srand48(time(nullptr)); // use time in seconds to set seed // lrand48() returns non-negative long integers // uniformly distributed over the interval [0, 2^31). // drand48() returns non-negative double precision floating-point // values uniformly distributed between [0.0, 1.0). cout << endl; cout << "5 long random numbers:" << endl; for (int i = 0; i < 5; ++i) cout << lrand48() << " "; cout << endl; cout << endl; cout << "5 double random numbers from [0, 1):" << endl; for (int i = 0; i < 5; ++i) cout << drand48() << " "; 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; }