Files Classes Functions Hierarchy
00001 00002 #include <ctime> 00003 #include <cstdlib> 00004 #include <iostream> 00005 using namespace std; 00006 00007 00008 #include <aclock.h> 00009 #include <clockmisc.h> 00010 00011 /* 00012 void generateRandomSeed() 00013 { 00014 srand( time(NULL) ); 00015 } 00016 */ 00017 00018 // The variation is still small, on my computer 00019 // between 3000 loops for 10 and 100 ms wait. 00020 00021 int generateRandomSeed(double const waitms) 00022 { 00023 double tm = 0.0; 00024 00025 aclock clk; 00026 00027 clk.measure(); 00028 00029 int sd=0; 00030 00031 int kmax; 00032 00033 int loops=0; 00034 00035 for ( ;tm<waitms; ) 00036 { 00037 kmax = rand() % 20; 00038 for (int k=1; k<kmax; ++k) 00039 sd += rand(); 00040 00041 clk.measure(); 00042 tm += clk.diff_ms(); 00043 00044 ++loops; 00045 } 00046 00047 if (sd<0) 00048 sd *= -1; 00049 00050 // cout << "loops=" << loops << endl; 00051 // cout << "sd=" << sd << endl; 00052 00053 return sd; 00054 } 00055 00056 00057 00058
1.5.8