package rune

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Rune.RngSource

Sourcetype key

PRNG key type representing the random state

Sourceval key : int -> key

Create a PRNG key from a seed value.

The seed is used to initialize the random state. Same seed produces same sequence of random numbers.

Sourceval split : ?n:int -> key -> key array

Split a PRNG key into multiple new keys.

split key n returns an array of n new independent keys derived from the input key. The original key should not be reused after splitting to maintain statistical guarantees.

  • parameter key

    The key to split

  • parameter n

    Number of new keys to generate (default: 2)

  • returns

    Array of new independent keys

Sourceval fold_in : key -> int -> key

Fold data into a key to derive a new key.

fold_in key data combines a key with integer data to produce a new key. Useful for deriving keys based on iteration indices or other structured data.

  • parameter key

    The base key

  • parameter data

    Integer data to fold into the key

  • returns

    New derived key

Sourceval to_int : key -> int

Convert key to integer representation for debugging.

to_int key returns the internal integer representation of the key. This is mainly useful for debugging and should not be used to recreate keys.

Sourceval uniform : key -> ('a, 'b) dtype -> int array -> ('a, 'b) t

Generate uniform random values in [0, 1).

uniform key dtype shape generates a tensor of the given shape with values uniformly distributed in the half-open interval [0, 1).

  • parameter key

    PRNG key for random generation

  • parameter dtype

    Data type of the output tensor

  • parameter shape

    Shape of the output tensor

  • returns

    Tensor with uniform random values

Sourceval normal : key -> ('a, 'b) dtype -> int array -> ('a, 'b) t

Generate standard normal random values.

normal key dtype shape generates a tensor of the given shape with values sampled from a standard normal distribution (mean=0, std=1).

  • parameter key

    PRNG key for random generation

  • parameter dtype

    Data type of the output tensor

  • parameter shape

    Shape of the output tensor

  • returns

    Tensor with normal random values

Sourceval randint : key -> min:int -> max:int -> int array -> int32_t

Generate random integers in a range.

randint key ~min ~max shape generates a tensor of integers uniformly distributed in the half-open interval [min, max).

  • parameter key

    PRNG key for random generation

  • parameter min

    Minimum value (inclusive)

  • parameter max

    Maximum value (exclusive)

  • parameter shape

    Shape of the output tensor

  • returns

    Tensor with random integer values

Sourceval bernoulli : key -> p:float -> int array -> uint8_t

Generate Bernoulli random values.

bernoulli key ~p shape generates a tensor of boolean values where each element is true with probability p.

  • parameter key

    PRNG key for random generation

  • parameter p

    Probability of true (must be in [0, 1])

  • parameter shape

    Shape of the output tensor

  • returns

    Tensor with boolean random values

Sourceval permutation : key -> int -> int32_t

Generate random permutation.

permutation key n generates a random permutation of integers from 0 to n-1.

  • parameter key

    PRNG key for random generation

  • parameter n

    Number of elements to permute

  • returns

    1-D tensor containing a random permutation

Sourceval shuffle : key -> ('a, 'b) t -> ('a, 'b) t

Randomly shuffle the first dimension of a tensor.

shuffle key x returns a copy of tensor x with its first dimension randomly shuffled.

  • parameter key

    PRNG key for random generation

  • parameter x

    Tensor to shuffle

  • returns

    Shuffled tensor

Sourceval categorical : key -> ?axis:int -> ('a, 'b) t -> int32_t

Sample from a categorical distribution.

categorical key logits ?axis samples indices from a categorical distribution defined by logits along the specified axis.

  • parameter key

    PRNG key for random generation

  • parameter logits

    Unnormalized log probabilities

  • parameter axis

    Axis along which to sample (default: -1)

  • returns

    Tensor of sampled indices

Sourceval truncated_normal : key -> ('a, 'b) dtype -> lower:'a -> upper:'a -> int array -> ('a, 'b) t

Generate random values from a truncated normal distribution.

truncated_normal key dtype ~lower ~upper shape generates values from a normal distribution truncated to the range lower, upper.

  • parameter key

    PRNG key for random generation

  • parameter dtype

    Data type of the output tensor

  • parameter lower

    Lower truncation bound

  • parameter upper

    Upper truncation bound

  • parameter shape

    Shape of the output tensor

  • returns

    Tensor with truncated normal random values