D - Bug in random.d
I was just looking through the Phobos source for the stream eof(), since someone said it was bad. On the way, I found a bug in random.d There's a static initialiser to seed it: static this() { ulong s; version(Win32) { QueryPerformanceCounter(&s); } version(linux) { // time.h // sys/time.h timeval tv; if (gettimeofday(&tv, null)) { // Some error happened - try time() instead s = time(null); } else { s = ((long)tv.tv_sec << 32) + tv.tv_usec; } } rand_seed((uint) s, (uint)(s >> 32)); } The problem is that QueryPerformanceCounter _can_ fail, so it should read version(Win32) { if(!QueryPerformanceCounter(&s)) { s = GetTickCount(); } } Granted that almost any hardware will have a performance counter, but it's not guaranteed, so best to be 100% correct. Matthew
Jan 29 2004