[−][src]Struct srand::Rand
Methods
impl<S> Rand<S> where
S: Source,
[src]
S: Source,
pub fn new(src: S) -> Rand<S>
[src]
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(()) }
pub fn seed(&mut self, seed: i64)
[src]
Seed uses the provided seed value to initialize the generator to a deterministic state.
pub fn int64(&mut self) -> i64
[src]
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(()) }
pub fn uint64(&mut self) -> u64
[src]
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(()) }
pub fn int32(&mut self) -> i32
[src]
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(()) }
pub fn uint32(&mut self) -> u32
[src]
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(()) }
pub fn int32n(&mut self, n: i32) -> i32
[src]
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(()) }
pub fn int64n(&mut self, n: i64) -> i64
[src]
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(()) }
pub fn float32(&mut self) -> f32
[src]
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(()) }
pub fn float64(&mut self) -> f64
[src]
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(()) }
pub fn shuffle<T>(&mut self, array: &mut Vec<T>)
[src]
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
impl<S: Source> Send for Rand<S> where
S: Send,
[src]
S: Send,
impl<S: Source> Sync for Rand<S> where
S: Sync,
[src]
S: Sync,
impl<S: Sized + Source> Clone for Rand<S> where
S: Clone,
[src]
S: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl<S> Unpin for Rand<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for Rand<S> where
S: UnwindSafe,
S: UnwindSafe,
impl<S> RefUnwindSafe for Rand<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,