Random number generation
Weighted
- A value with a particular weight compared to other valuesXorShiftState
rctx
RandRes
Rng
- A random number generatorfor Rng
- Extension methods for random number generatorsof Rng for @RandRes
of Rng for XorShiftState
RandRes
Rng
- Create a random number generator with a system specified seedrandom
- Returns a random uint, using the task's based random number generator.seed
- Create a new random seed for seeded_rngseeded_rng
- Create a random number generator using the specified seedseeded_xorshift
task_rng
- Gives back a lazily initialized task-local random number generator, seeded by the systemtls_rng_state
xorshift
rand::rustrt
Weighted
type Weighted<T> = {weight: uint, item: T,}
A value with a particular weight compared to other values
XorShiftState
type XorShiftState = {mut x: u32, mut y: u32, mut z: u32, mut w: u32,}
rctx
RandRes
struct RandRes {
c: *rctx,
}
Rng
A random number generator
next
fn next() -> u32
Return the next random integer
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 in the interval [0,1]
gen_f32
fn gen_f32() -> f32
Return a random f32 in the interval [0,1]
gen_f64
fn gen_f64() -> f64
Return a random f64 in the interval [0,1]
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
for @RandRes
next
fn next() -> u32
Rng
for XorShiftState
next
fn next() -> u32
RandRes
fn RandRes(c: *rctx) -> RandRes
Rng
fn Rng() -> Rng
Create a random number generator with a system specified seed
random
fn random() -> uint
Returns a random uint, using the task's based random number generator.
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
task_rng
fn task_rng() -> Rng
Gives back a lazily initialized task-local random number generator, seeded by the system. Intended to be used in method chaining style, ie task_rng().gen_int().
tls_rng_state
fn tls_rng_state(_v: @RandRes)
xorshift
fn xorshift() -> Rng