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], exn : Exception) -> unit

Parameters

NameTypeNotes
buf[u8]
exnException

Returns: unit

random_u32 function
fn(exn : Exception) -> u32

Parameters

NameTypeNotes
exnException

Returns: u32

random_u64 function
fn(exn : Exception) -> u64

Parameters

NameTypeNotes
exnException

Returns: u64

random_f64 function
fn(exn : Exception) -> f64

Parameters

NameTypeNotes
exnException

Returns: f64

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

Parameters

NameTypeNotes
mini64
maxi64
exnException

Returns: i64

uuid_v4 function
fn(exn : Exception) -> String

Parameters

NameTypeNotes
exnException

Returns: String