Add _system_random for Darwin

This commit is contained in:
gingerBill
2022-05-15 23:46:32 +01:00
parent 2a58bceb56
commit 4eba2bb8d9

View File

@@ -0,0 +1,21 @@
package rand
import "core:sys/darwin"
_system_random :: proc() -> u32 {
for {
value: u32
ret := darwin.syscall_getentropy(([^]u8)(&value), 4)
if ret < 0 {
switch ret {
case -4: // EINTR
continue
case -78: // ENOSYS
panic("getentropy not available in kernel")
case:
panic("getentropy failed")
}
}
return value
}
}