#include <sys/random.h>

sys/random.h Kernel.framework

3 functions

functionread_random

void read_random(void* buffer, u_int numBytes)
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu osfmk/prng/prng_random.c
Fills buffer with numBytes of cryptographically strong random bytes from the kernel PRNG (corecrypto kernel PRNG seeded from the entropy pool). The generator is refreshed before generating, so the output is suitable for keys and other security-sensitive uses. May be relatively expensive; see read_frandom for a cheaper alternative.

functionread_frandom

void read_frandom(void* buffer, u_int numBytes)
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu osfmk/prng/prng_random.c
Fills buffer with numBytes of random bytes, historically from a faster, lower-strength generator. In current xnu it defers to the same kernel PRNG as read_random once corecrypto is initialized, falling back to the early-boot DRBG before then; unlike read_random it does not force a refresh first.

functionwrite_random

int write_random(void* buffer, u_int numBytes)
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu osfmk/prng/prng_random.c
Contributes numBytes from buffer as entropy to the kernel PRNG. Input longer than SHA512_DIGEST_LENGTH is hashed with SHA-512 first; the resulting seed is passed to the PRNG's reseed function and then cleared. Always returns 0.