pub trait RandomInt {
fn gen_uint(&mut self, bits: usize) -> Int;
fn gen_int(&mut self, bits: usize) -> Int;
fn gen_uint_below(&mut self, bound: &Int) -> Int;
fn gen_int_range(&mut self, lbound: &Int, ubound: &Int) -> Int;
}
Expand description
Trait for generating random Int
s.
Example
Generate a random Int
of size 256
bits:
extern crate rand;
extern crate ramp;
use ramp::RandomInt;
fn main() {
let mut rng = rand::thread_rng();
let big_i = rng.gen_int(256);
}
Required Methods
fn gen_uint_below(&mut self, bound: &Int) -> Int
fn gen_uint_below(&mut self, bound: &Int) -> Int
Generate a random unsigned Int
less than the given bound.
Fails when the bound is zero or negative.
fn gen_int_range(&mut self, lbound: &Int, ubound: &Int) -> Int
fn gen_int_range(&mut self, lbound: &Int, ubound: &Int) -> Int
Generate a random Int
within the given range.
The lower bound is inclusive; the upper bound is exclusive.
Fails when the upper bound is not greater than the lower bound.