转自:windows下srand48()和drand48()的问题
1 #ifndef DRAND48_H 2 #define DRAND48_H 3 4 #include <stdlib.h> 5 6 #define m 0x100000000LL 7 #define c 0xB16 8 #define a 0x5DEECE66DLL 9 10 static unsigned long long seed = 1; 11 12 double drand48(void) 13 { 14 seed = (a * seed + c) & 0xFFFFFFFFFFFFLL; 15 unsigned int x = seed >> 16; 16 return ((double)x / (double)m); 17 18 } 19 20 void srand48(unsigned int i) 21 { 22 seed = (((long long int)i) << 16) | rand(); 23 } 24 25 #endif