aboutsummaryrefslogtreecommitdiff
path: root/src/os.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/os.cpp')
-rw-r--r--src/os.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/os.cpp b/src/os.cpp
index 16d6847d4e..26ed0dc4e1 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -1462,6 +1462,14 @@ static void init_rand() {
unsigned seed;
memcpy(&seed, ptr_random, sizeof(seed));
srand(seed);
+#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
+ unsigned seed;
+ size_t len = sizeof(seed);
+ int mib[2] = { CTL_KERN, KERN_ARND };
+ if (sysctl(mib, 2, &seed, &len, NULL, 0) != 0) {
+ zig_panic("unable to query random data from sysctl");
+ }
+ srand(seed);
#else
int fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
if (fd == -1) {