转自:windows下srand48()和drand48()的问题


[转]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

 

 

相关文章:

  • 2021-07-13
  • 2021-09-05
  • 2021-05-11
  • 2022-02-25
  • 2022-12-23
  • 2021-06-27
  • 2021-12-24
  • 2022-03-06
猜你喜欢
  • 2021-11-11
  • 2021-09-06
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案