discord test stars

About

Random numbers in the Mys programming language.

Project: https://github.com/mys-lang/package-random

Examples

Use pseudo random numbers.

from random.pseudo import random
from random.pseudo import randint
from random.pseudo import randfloat
from random.pseudo import randbytes

func main():
    print("random():            ", random())
    print("randint(-5, 10):     ", randint(-5, 10))
    print("randfloat(-1.0, 3.5):", randfloat(-1.0, 3.5))
    print("randbytes(5):        ", randbytes(5))

Build and run:

 mys run
 Reading package configuration (0 seconds)
 Building (0.01 seconds)
random():             0.898648
randint(-5, 10):      1
randfloat(-1.0, 3.5): 2.61118
randbytes(5):         b"\x40\x27\x00\x2e\x47"

API

Pseudo random numbers

Cheap pseudo random numbers.

func random() -> f64:
    Returns a pseudo random floating point number in the range [0.0,
    1.0] (inclusive).
func randint(minimum: i64, maximum: i64) -> i64:
    Returns a pseudo random integer number in the range [minimum,
    maximum] (inclusive).
func randfloat(minimum: f64, maximum: f64) -> f64:
    Returns a pseudo random floating point number in the range
    [minimum, maximum] (inclusive).
func randbytes(length: i64) -> bytes:
    Returns given number of pseudo random bytes.
@generic(T)
func shuffle(values: [T]):
    Shuffle the values in place.

Cryptographically safe random numbers

Random numbers that should be cryptographically safe. Much slower than pseudo random numbers.

func random() -> f64:
    Returns a cryptographically safe random floating point number in
    the range [0.0, 1.0] (inclusive).
func randint(minimum: i64, maximum: i64) -> i64:
    Returns a cryptographically safe random integer number in the range
    [minimum, maximum] (inclusive).
func randfloat(minimum: f64, maximum: f64) -> f64:
    Returns a cryptographically safe random floating point number in
    the range [minimum, maximum] (inclusive).
func randbytes(length: i64) -> bytes:
    Returns given number of cryptographically safe random bytes.
@generic(T)
func shuffle(values: [T]):
    Shuffle the values in place.