// // Programmer: Craig Stuart Sapp // Creation Date: Mon Oct 18 06:30:47 PDT 1999 // Last Modified: Fri Dec 31 15:38:13 PST 1999 // Web Address: http://www-ccrma.stanford.edu/~craig/utility/randnum/randnum.cpp // Syntax: C++ // $Smake: g++ -O3 -o %b %f && strip %b // // Description: High quality random numbers with excellent seeding // behaviour. // #include #include #include #ifdef VISUAL #include typedef LONGLONG int64bits; #else typedef long long int int64bits; #include /* for millisleep function */ #endif unsigned int randomseed(void); int getInitialDigit(void); char* getDigits(int count); int main(int argc, char** argv) { int repetition; if (argc != 2) { repetition = 1; } else { repetition = atoi(argv[1]); } srand48(randomseed()); time_t now; struct tm *currenttime; now = time(NULL); currenttime = localtime(&now); for (int i=0; itm_year % 100; if (currenttime->tm_mon < 9) { cout << "0"; } cout << currenttime->tm_mon + 1; if (currenttime->tm_mday < 10) { cout << "0"; } cout << currenttime->tm_mday; if (currenttime->tm_hour < 10) { cout << "0"; } cout << currenttime->tm_hour; if (currenttime->tm_min < 10) { cout << "0"; } cout << currenttime->tm_min; if (currenttime->tm_sec < 10) { cout << "0"; } cout << currenttime->tm_sec; cout << getInitialDigit() << getDigits(5) << '\n'; } return 0; } int getInitialDigit(void) { int output = 0; while (output < 1 || output > 8) { output = (int) (drand48() * 10); } return output; } char* getDigits(int count) { static char output[1024] = {0}; if (count > 1000) { cout << "Error: too many digits requested" << endl; exit(1); } for (int i=0; i