pub struct Rand<S>where
S: Source,{ /* private fields */ }
Implementations§
Source§impl<S> Rand<S>where
S: Source,
impl<S> Rand<S>where
S: Source,
Sourcepub fn new(src: S) -> Rand<S>
pub fn new(src: S) -> Rand<S>
Creates a new Rand that uses random values from src to generate other random values.
§Examples
use srand::Rand;
use srand::RngSource;
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
Ok(())
}
Sourcepub fn seed(&mut self, seed: i64)
pub fn seed(&mut self, seed: i64)
Seed uses the provided seed value to initialize the generator to a deterministic state.
Sourcepub fn int64(&mut self) -> i64
pub fn int64(&mut self) -> i64
Returns a non-negative pseudo-random 63-bit integer as an i64.
§Examples
use srand::{Rand,RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.int64());
Ok(())
}
Sourcepub fn uint64(&mut self) -> u64
pub fn uint64(&mut self) -> u64
Returns a pseudo-random 64-bit value as a u64.
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.uint64());
Ok(())
}
Sourcepub fn int32(&mut self) -> i32
pub fn int32(&mut self) -> i32
i32 returns a non-negative pseudo-random 31-bit integer as an i32.
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.int32());
Ok(())
}
Sourcepub fn uint32(&mut self) -> u32
pub fn uint32(&mut self) -> u32
Returns a pseudo-random 32-bit value as a u32.
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.uint32());
Ok(())
}
Sourcepub fn int32n(&mut self, n: i32) -> i32
pub fn int32n(&mut self, n: i32) -> i32
Returns an i32, a non-negative pseudo-random number in [0,n). It panics if n <= 0.
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.int32n(90000001));
Ok(())
}
Sourcepub fn int64n(&mut self, n: i64) -> i64
pub fn int64n(&mut self, n: i64) -> i64
Returns an i64, a non-negative pseudo-random number in [0,n). It panics if n <= 0.
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.int64n(90000001));
Ok(())
}
Sourcepub fn float32(&mut self) -> f32
pub fn float32(&mut self) -> f32
Returns a f32, a pseudo-random number in [0.0,1.0).
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.float32());
Ok(())
}
Sourcepub fn float64(&mut self) -> f64
pub fn float64(&mut self) -> f64
Returns a f64, a pseudo-random number in [0.0,1.0).
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
println!("n: {}", r.float64());
Ok(())
}
Sourcepub fn shuffle<T>(&mut self, array: &mut Vec<T>)
pub fn shuffle<T>(&mut self, array: &mut Vec<T>)
Shuffle pseudo-randomizes the order of elements.
§Examples
use srand::{Rand, RngSource};
fn main() -> std::io::Result<()> {
let mut r: Rand<_> = Rand::new(RngSource::new(1));
let mut v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
println!("result: {:?}", r.shuffle(&mut v));
println!("shuffled array: {:?}", v);
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Rand<S>where
S: Freeze,
impl<S> RefUnwindSafe for Rand<S>where
S: RefUnwindSafe,
impl<S> Unpin for Rand<S>where
S: Unpin,
impl<S> UnwindSafe for Rand<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more