Random number generation
weighted
- A value with a particular weight compared to other valuesrng
- A random number generatorextensions for rng
- Extension methods for random number generatorsrng of rng for @rand_res
rng of rng for xorshift_state
rng
- Create a random number generator with a system specified seedseed
- Create a new random seed for seeded_rngseeded_rng
- Create a random number generator using the specified seedseeded_xorshift
xorshift
weighted
type weighted<T> = {weight: uint, item: T,}
A value with a particular weight compared to other values
rng
A random number generator
next
fn next() -> u32
Return the next random integer
extensions for rng
Extension methods for random number generators
gen_int
fn gen_int() -> int
Return a random int
gen_int_range
fn gen_int_range(start: int, end: int) -> int
Return an int randomly chosen from the range [start, end), failing if start >= end
gen_i8
fn gen_i8() -> i8
Return a random i8
gen_i16
fn gen_i16() -> i16
Return a random i16
gen_i32
fn gen_i32() -> i32
Return a random i32
gen_i64
fn gen_i64() -> i64
Return a random i64
gen_uint
fn gen_uint() -> uint
Return a random uint
gen_uint_range
fn gen_uint_range(start: uint, end: uint) -> uint
Return a uint randomly chosen from the range [start, end), failing if start >= end
gen_u8
fn gen_u8() -> u8
Return a random u8
gen_u16
fn gen_u16() -> u16
Return a random u16
gen_u32
fn gen_u32() -> u32
Return a random u32
gen_u64
fn gen_u64() -> u64
Return a random u64
gen_float
fn gen_float() -> float
Return a random float
gen_f32
fn gen_f32() -> f32
Return a random f32
gen_f64
fn gen_f64() -> f64
Return a random f64
gen_char
fn gen_char() -> char
Return a random char
gen_char_from
fn gen_char_from(chars: str) -> char
Return a char randomly chosen from chars, failing if chars is empty
gen_bool
fn gen_bool() -> bool
Return a random bool
gen_weighted_bool
fn gen_weighted_bool(n: uint) -> bool
Return a bool with a 1 in n chance of true
gen_str
fn gen_str(len: uint) -> str
Return a random string of the specified length composed of A-Z,a-z,0-9
gen_bytes
fn gen_bytes(len: uint) -> ~[u8]
Return a random byte string of the specified length
choose
fn choose<T: copy>(values: ~[T]) -> T
Choose an item randomly, failing if values is empty
choose_option
fn choose_option<T: copy>(values: ~[T]) -> option<T>
Choose some(item) randomly, returning none if values is empty
choose_weighted
fn choose_weighted<T: copy>(v: ~[weighted<T>]) -> T
Choose an item respecting the relative weights, failing if the sum of the weights is 0
choose_weighted_option
fn choose_weighted_option<T: copy>(v: ~[weighted<T>]) -> option<T>
Choose some(item) respecting the relative weights, returning none if the sum of the weights is 0
weighted_vec
fn weighted_vec<T: copy>(v: ~[weighted<T>]) -> ~[T]
Return a vec containing copies of the items, in order, where the weight of the item determines how many copies there are
shuffle
fn shuffle<T: copy>(values: ~[T]) -> ~[T]
Shuffle a vec
shuffle_mut
fn shuffle_mut<T>(&&values: ~[mut T])
Shuffle a mutable vec in place
rng of rng for @rand_res
next
fn next() -> u32
rng of rng for xorshift_state
next
fn next() -> u32
rng
fn rng() -> rng
Create a random number generator with a system specified seed
seed
fn seed() -> ~[u8]
Create a new random seed for seeded_rng
seeded_rng
fn seeded_rng(seed: ~[u8]) -> rng
Create a random number generator using the specified seed. A generator constructed with a given seed will generate the same sequence of values as all other generators constructed with the same seed. The seed may be any length.
seeded_xorshift
fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> rng
xorshift
fn xorshift() -> rng