clock_t clock();
#include <iostream>
#include <ctime>
int main() {
using namespace std;
clock_t qStartTime;
clock_t qEndTime;
const unsigned int kuiNumberCount = 20000000;
const unsigned int kuiModulus = 6;
// Time the random number generator
qStartTime = clock();
for (unsigned int uiIndex = 0; uiIndex < kuiNumberCount; ++uiIndex) {
unsigned int uiInteger = rand();
unsigned int uiRand = (uiInteger % kuiModulus);
}
qEndTime = clock();
double dElapsedSecs = (double)(qEndTime - qStartTime)/CLOCKS_PER_SEC;
cout << "Generating " << kuiNumberCount
<< " random numbers between 0 and "
<< (kuiModulus - 1) << " takes "
<< dElapsedSecs << " seconds." << endl;
return 0;
}
© 20072023 XoaX.net LLC. All rights reserved.