truerand.c 306 B

1234567891011121314151617
  1. #include <u.h>
  2. #include <libc.h>
  3. ulong
  4. truerand(void)
  5. {
  6. ulong x;
  7. static int randfd = -1;
  8. if(randfd < 0)
  9. randfd = open("/dev/random", OREAD|OCEXEC);
  10. if(randfd < 0)
  11. sysfatal("can't open /dev/random");
  12. if(read(randfd, &x, sizeof(x)) != sizeof(x))
  13. sysfatal("can't read /dev/random");
  14. return x;
  15. }