drand48.c 358 B

12345678910111213141516171819
  1. #include <stdlib.h>
  2. #include <inttypes.h>
  3. uint64_t __rand48_step(unsigned short *xi, unsigned short *lc);
  4. extern unsigned short __seed48[7];
  5. double erand48(unsigned short s[3])
  6. {
  7. union {
  8. uint64_t u;
  9. double f;
  10. } x = { 0x3ff0000000000000ULL | __rand48_step(s, __seed48+3)<<4 };
  11. return x.f - 1.0;
  12. }
  13. double drand48(void)
  14. {
  15. return erand48(__seed48);
  16. }