Class crypto_rng

Lua interface to synchronous Random Number Generators (RNG).

Methods

crypto_rng:generate (n[, seed]) Generates random bytes, optionally reseeding first.
crypto_rng:getbytes (n) Generates random bytes without reseeding.
crypto_rng:info () Returns algorithm information.
crypto_rng:new ([algname]) Creates a new RNG object.
crypto_rng:reset (seed) Reseeds the RNG.


Methods

crypto_rng:generate (n[, seed])
Generates random bytes, optionally reseeding first.

Parameters:

  • n integer number of bytes to generate
  • seed string optional seed data (optional)

Returns:

    string random bytes

Raises:

on generation failure
crypto_rng:getbytes (n)
Generates random bytes without reseeding.

Parameters:

  • n integer number of bytes to generate

Returns:

    string random bytes

Raises:

on generation failure
crypto_rng:info ()
Returns algorithm information.

Returns:

    table with fields driver_name (string) and seedsize (integer)
crypto_rng:new ([algname])
Creates a new RNG object.

Parameters:

  • algname string algorithm name; defaults to "stdrng" (optional)

Returns:

    crypto_rng

Raises:

on allocation or initialization failure

Usage:

    local rng = require("crypto").rng
    local r = rng()  -- uses "stdrng"
crypto_rng:reset (seed)
Reseeds the RNG.

Parameters:

Raises:

on reseed failure
generated by LDoc 1.5.0 Last updated 2026-03-31 12:21:45