Module crypto/random

crypto/random

Cryptographically secure random number generation. Uses OS entropy sources (getrandom on Linux, arc4random_buf on macOS, BCryptGenRandom on Windows, getentropy on WASI).

Example

{ random_u64, uuid_v4 } :: import "std/crypto/random";

id := uuid_v4();  // "550e8400-e29b-41d4-a716-446655440000"

Types

CryptoError

Errors that can occur during cryptographic random operations.

Variants

VariantFieldsDescription
Unavailable

Platform does not support secure random generation.

Othermsg: String

Other platform-specific error.

Trait Implementations

impl(CryptoError, ToString(...))
to_string : (self -> match(self, .Unavailable => `crypto: platform random unavailable`, .Other(msg) => `crypto error: ${msg}` ) )
impl(CryptoError, Error())

Functions

random_bytes function
fn(buf : *(u8), size : usize, using(exn : Exception)) -> unit

Parameters

NameTypeNotes
buf*(u8)
sizeusize

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: unit

random_u32 function
fn(using(exn : Exception)) -> u32

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: u32

random_u64 function
fn(using(exn : Exception)) -> u64

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: u64

random_f64 function
fn(using(exn : Exception)) -> f64

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: f64

random_range function
fn(min : i64, max : i64, using(exn : Exception)) -> i64

Parameters

NameTypeNotes
mini64
maxi64

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: i64

uuid_v4 function
fn(using(exn : Exception)) -> String

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: String