xur_

> module

std::random

random number generation

use std::random; feature random in the browser

std::random generates random values with rand's thread-local generator, a cryptographically secure generator seeded from the OS.

> functions

# bool() -> bool

A random boolean.

# bytes(len: usize) -> bytes

len random bytes.

# choice(list: list<T>) -> T

A random item of list. An empty list is a runtime error.

# float() -> f64

A random float in [0.0, 1.0).

# int(min: i64, max: i64) -> i64

A random integer in the inclusive range [min, max]. min greater than max is a runtime error.

# shuffle(list: list) -> list<T>

A new list with the items of list in random order; list is unchanged.

> examples

use std::random;
use std::io;

fn main() {
    io::println("dice: {}", random::int(1, 6));
    io::println("coin: {}", random::bool());

    let items = ["a", "b", "c"];
    io::println("pick: {}", random::choice(items));
    io::println("shuffled: {}", random::shuffle(items));
}