Pyro

A scripting language for people who enjoy the simpler things in life.

Version 0.5.37

$std::prng


This module uses a 64-bit Mersenne Twister to generate pseudo-random numbers.

The output of the generator is completely deterministic and depends only on the initial seed value, i.e. the sequence of numbers generated will always be identical for a given seed.

The generator is automatically initialized at startup using a random seed but you can reinitialize the generator at any time by calling seed(arg). This reseeds the generator using the argument's 64-bit hash value.

Functions

rand_float() -> f64

Returns a uniformly-distributed random float from the half-open interval [0, 1), i.e. the interval from zero up to but not including 1. The generator produces floats with 53 bits of precision.

rand_int(n: i64) -> i64

Returns a uniformly-distributed random integer from the half-open interval [0, n), i.e. the interval from zero up to but not including n, where n is a positive integer.

rand_int_in_range(lower: i64, upper: i64) -> i64

Returns a uniformly-distributed random integer from the half-open interval [lower, upper), i.e. the interval from lower up to but not including upper.

The arguments can be positive or negative or mixed as long as lower is less than or equal to upper.

seed(arg: any)

Seeds (or re-seeds) the generator using the argument's 64-bit hash value. This is an alias for seed_with_hash().

seed_with_array(arg: buf|str)

Seeds (or re-seeds) the generator using the content of a string or buffer, treated as an array of bytes. Uses up to the first 2,496 bytes of content.

If arg contains less than 8 bytes of content, this is equivalent to calling seed_with_hash().

seed_with_hash(arg: any)

Seeds (or re-seeds) the generator using the argument's 64-bit hash value.