Pyro

A dynamically-typed, garbage-collected scripting language.

Version 0.23.1

std::prng


This module contains utilities for generating pseudo-random numbers using the xoshiro256** algorithm.

The module-level functions use a global generator initialized with a random seed.

To generate a repeatable sequence of pseudo-random numbers, use a Generator instance with a known seed.

Functions

rand_float() -> f64

Returns a uniformly-distributed random float from the half-open interval [0.0, 1.0) — i.e. the interval from zero up to but not including 1.0.

rand_float_in_range(x: f64, y: f64) -> f64

Returns a uniformly-distributed random float from the half-open interval [x, y) — i.e. the interval from x up to but not including y. The bounds can be positive, negative, or mixed, but x must be less than y.

rand_int() -> i64
rand_int(n: i64) -> i64

Returns a uniformly-distributed random integer.

  • If called with zero arguments, returns an integer from the full i64 range.
  • If called with a single positive integer argument n, returns an integer from the half-open interval [0, n) — i.e. the interval from zero up to but not including n.
rand_int_in_range(n: i64, m: i64) -> i64

Returns a uniformly-distributed random integer from the half-open interval [n, m) — i.e. the interval from n up to but not including m. The bounds can be positive, negative, or mixed, but n must be less than m.

Classes

Generator() -> Generator
Generator(seed: i64) -> Generator

Returns a new pseudo-random number generator.

If no seed value is specified, the generator will be automatically initialized with a random seed.

Generator instances support the following methods:

:rand_float() -> f64

Returns a uniformly-distributed random float from the half-open interval [0.0, 1.0) — i.e. the interval from zero up to but not including 1.0.

:rand_float_in_range(x: f64, y: f64) -> f64

Returns a uniformly-distributed random float from the half-open interval [x, y) — i.e. the interval from x up to but not including y. The bounds can be positive, negative, or mixed, but x must be less than y.

:rand_int() -> i64
:rand_int(n: i64) -> i64

Returns a uniformly-distributed random integer.

  • If called with zero arguments, returns an integer from the full i64 range.
  • If called with a single positive integer argument n, returns an integer from the half-open interval [0, n) — i.e. the interval from zero up to but not including n.
:rand_int_in_range(n: i64, m: i64) -> i64

Returns a uniformly-distributed random integer from the half-open interval [n, m) — i.e. the interval from n up to but not including m. The bounds can be positive, negative, or mixed, but n must be less than m.

:seed(n: i64)

Seeds the generator using the number n.