Manuscript Documentation
v0.1.0

@std/random.ms#

Import each required symbol with import Name from "@std/random.ms".

Entropy Interface#

A source of cryptographically secure random bytes.

Manuscript
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.

Manuscript
fn bytes(count: Int) -> Result[Bytes, RandomError]

RandomError Alternative#

Errors returned when random input is invalid or entropy generation fails.

Manuscript
type RandomError:
    case InvalidInput
    case LimitExceeded
    case Failed(message: String)
Manuscript
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.

Manuscript
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.

Manuscript
case InvalidInput

RandomError.LimitExceeded#

Reserved for requests that exceed a configured random-generation budget; the current operations do not return it.

Manuscript
case LimitExceeded

RandomError.Failed.message#

The source’s failure text, which message() returns verbatim.

Manuscript
message: String

RandomError.Error.message#

Returns the Failed text verbatim, and otherwise the fixed diagnostic random: <reason>.

Manuscript
fn message() -> String:

entropy Function#

Returns the operating system’s cryptographic entropy source.

Manuscript
fn entropy() -> Entropy:

secure_int Function#

Returns a secure integer at least min and below max_exclusive when supplied.

Manuscript
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.

Manuscript
fn uuid_v4(entropy: Entropy) -> Result[String, RandomError]: