crypto/random

sourcecrypto/random.sx

arc4random_buf

when posixprivate
extern (C) fn arc4random_buf(buf: ref void, len: usize) void = trust { ... } = "arc4random_buf"

arc4random_uniform

when posixprivate
extern (C) fn arc4random_uniform(upper_bound: u32) u32 = trust { ... } = "arc4random_uniform"

BCryptGenRandom

when windowsprivate
extern (C) fn BCryptGenRandom(hAlgorithm: ref void, pbBuffer: ref void, cbBuffer: u32, dwFlags: u32) i32 = trust { ... } = "BCryptGenRandom"

random_bytes

pub fn random_bytes(buf: ref void, len: usize) void

Fill `buf` with `len` cryptographically secure random bytes.

random_u64

pub fn random_u64() u64

Return a cryptographically secure random u64.

random_u32_below

pub fn random_u32_below(upper_bound: u32) u32

Return a cryptographically secure random u32 in (0, upper_bound) without modulo bias. Requires upper_bound > 0.

random_uuid

pub fn random_uuid() ref u8 = trust { ... }

Allocate and return a null-terminated UUID v4 string (37 bytes: 36 chars + null). The caller is responsible for freeing the returned pointer.

Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx (RFC 4122)