@std/random.ms#
Import each required symbol with import Name from "@std/random.ms".
Entropy Interface#
A source of cryptographically secure random bytes.
interface Entropy:
fn bytes(count: Int) -> Result[Bytes, RandomError]Entropy.bytes#
Returns exactly count unpredictable bytes, with count from 0 through 16 MiB (16777216).
A negative or larger count returns InvalidInput; a source failure returns Failed. The operating system source observes task cancellation between 64 KiB chunks.
fn bytes(count: Int) -> Result[Bytes, RandomError]RandomError Alternative#
Errors returned when random input is invalid or entropy generation fails.
type RandomError:
case InvalidInput
case LimitExceeded
case Failed(message: String)impl Error for RandomError:
fn message() -> String:RandomError.Failed#
The entropy source could not produce bytes, or returned a different number of bytes than requested.
case Failed(message: String)RandomError.InvalidInput#
The requested byte count is negative or above 16 MiB, or secure_int was given min not below max_exclusive.
case InvalidInputRandomError.LimitExceeded#
Reserved for requests that exceed a configured random-generation budget; the current operations do not return it.
case LimitExceededRandomError.Failed.message#
The source’s failure text, which message() returns verbatim.
message: StringRandomError.Error.message#
Returns the Failed text verbatim, and otherwise the fixed diagnostic random: <reason>.
fn message() -> String:entropy Function#
Returns the operating system’s cryptographic entropy source.
fn entropy() -> Entropy:secure_int Function#
Returns a secure integer at least min and below max_exclusive when supplied.
fn secure_int(entropy: Entropy, min: Int, max_exclusive: Optional[Int] = none) -> Result[Int, RandomError]:uuid_v4 Function#
Creates a version-4 UUID using the supplied cryptographic entropy source.
fn uuid_v4(entropy: Entropy) -> Result[String, RandomError]: