aboutsummaryrefslogtreecommitdiff
path: root/core/math/rand/system_darwin.odin
blob: 756f7fcae2d4ecbc9296ba27c7952cfc7da4128a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package rand

import "core:sys/darwin"

@(require_results)
_system_random :: proc() -> u64 {
	for {
		value: u64
		ret := darwin.syscall_getentropy(([^]u8)(&value), size_of(value))
		if ret < 0 {
			switch ret {
			case -4: // EINTR
				continue
			case -78: // ENOSYS
				panic("getentropy not available in kernel")
			case:
				panic("getentropy failed")
			}
		}
		return value
	}
}