aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-05-15 23:46:32 +0100
committergingerBill <bill@gingerbill.org>2022-05-15 23:46:32 +0100
commit4eba2bb8d9f4f4ec246d268ee382788062cfff16 (patch)
tree29c876c41ba908be2c1f378fa10f9ba2180a5249
parent2a58bceb5674c9af75dd217a7891869b4316f2f9 (diff)
Add `_system_random` for Darwin
-rw-r--r--core/math/rand/system_darwin.odin21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/math/rand/system_darwin.odin b/core/math/rand/system_darwin.odin
new file mode 100644
index 000000000..f51e4473e
--- /dev/null
+++ b/core/math/rand/system_darwin.odin
@@ -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
+ }
+} \ No newline at end of file