/**************************************************************** Copyright (C): University of Michigan Project: ENG101/300 - Class example File: rand3.cpp Purpose: An example of the rand() function: Convert the output of the rand() function to a double between 0 and 1 inclusive. In this application the sequence is seeded by the time function. Compiler: g++ Programmer: Alex Bielajew Revision Date: 10/01/2103 ****************************************************************/ /* Remarks: Convert the output of the rand() function to a double between 0 and 1 inclusive. In this application the sequence is seeded by the time function. */ //File: rand3.cpp #include #include #include // Need this for the rand() and srand() functions #include // Need this for the time() function using namespace std; int main(void) { cout << "RAND_MAX = " << RAND_MAX << "\n\n"; srand(static_cast(time(NULL))); // Seed the random number generator int nRandoms = 10; cout << "The first " << nRandoms << " random numbers are...\n"; for(int i = 1; i <= nRandoms; i = i + 1) { /////////////////////////////////////////////////////////// double randomDouble = rand()/static_cast(RAND_MAX); /////////////////////////////////////////////////////////// cout << "Random number " //<< setw(2) << i << " = " << randomDouble // Random double between 0 and 1 inclusive << "\n"; } return 0; }