system_darwin.odin 353 B

123456789101112131415161718192021
  1. package rand
  2. import "core:sys/darwin"
  3. _system_random :: proc() -> u32 {
  4. for {
  5. value: u32
  6. ret := darwin.syscall_getentropy(([^]u8)(&value), 4)
  7. if ret < 0 {
  8. switch ret {
  9. case -4: // EINTR
  10. continue
  11. case -78: // ENOSYS
  12. panic("getentropy not available in kernel")
  13. case:
  14. panic("getentropy failed")
  15. }
  16. }
  17. return value
  18. }
  19. }