Add rand.init_as_system to allow for system-level based random number generation

This commit is contained in:
gingerBill
2022-05-15 23:43:20 +01:00
parent fdcf08410c
commit 2a58bceb56
3 changed files with 56 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
package rand
import win32 "core:sys/windows"
_system_random :: proc() -> u32 {
value: u32
status := win32.BCryptGenRandom(nil, ([^]u8)(&value), 4, win32.BCRYPT_USE_SYSTEM_PREFERRED_RNG)
if status < 0 {
panic("BCryptGenRandom failed")
}
return value
}