浏览代码

Add `_system_random` for Darwin

gingerBill 3 年之前
父节点
当前提交
4eba2bb8d9
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      core/math/rand/system_darwin.odin

+ 21 - 0
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
+	}
+}