Struct fastrand::Rng [−][src]
A random number generator.
Implementations
impl Rng
[src]
pub fn new() -> Rng
[src]
Creates a new random number generator.
pub fn with_seed(seed: u64) -> Self
[src]
Creates a new random number generator with the initial seed.
pub fn alphabetic(&self) -> char
[src]
Generates a random char
in ranges a-z and A-Z.
pub fn alphanumeric(&self) -> char
[src]
Generates a random char
in ranges a-z, A-Z and 0-9.
pub fn bool(&self) -> bool
[src]
Generates a random bool
.
pub fn digit(&self, base: u32) -> char
[src]
Generates a random digit in the given base
.
Digits are represented by char
s in ranges 0-9 and a-z.
Panics if the base is zero or greater than 36.
pub fn f32(&self) -> f32
[src]
Generates a random f32
in range 0..1
.
pub fn f64(&self) -> f64
[src]
Generates a random f64
in range 0..1
.
pub fn i8(&self, range: impl RangeBounds<i8>) -> i8
[src]
Generates a random i8
in the given range.
Panics if the range is empty.
pub fn i16(&self, range: impl RangeBounds<i16>) -> i16
[src]
Generates a random i16
in the given range.
Panics if the range is empty.
pub fn i32(&self, range: impl RangeBounds<i32>) -> i32
[src]
Generates a random i32
in the given range.
Panics if the range is empty.
pub fn i64(&self, range: impl RangeBounds<i64>) -> i64
[src]
Generates a random i64
in the given range.
Panics if the range is empty.
pub fn i128(&self, range: impl RangeBounds<i128>) -> i128
[src]
Generates a random i128
in the given range.
Panics if the range is empty.
pub fn isize(&self, range: impl RangeBounds<isize>) -> isize
[src]
Generates a random isize
in the given range.
Panics if the range is empty.
pub fn lowercase(&self) -> char
[src]
Generates a random char
in range a-z.
pub fn seed(&self, seed: u64)
[src]
Initializes this generator with the given seed.
pub fn shuffle<T>(&self, slice: &mut [T])
[src]
Shuffles a slice randomly.
pub fn u8(&self, range: impl RangeBounds<u8>) -> u8
[src]
Generates a random u8
in the given range.
Panics if the range is empty.
pub fn u16(&self, range: impl RangeBounds<u16>) -> u16
[src]
Generates a random u16
in the given range.
Panics if the range is empty.
pub fn u32(&self, range: impl RangeBounds<u32>) -> u32
[src]
Generates a random u32
in the given range.
Panics if the range is empty.
pub fn u64(&self, range: impl RangeBounds<u64>) -> u64
[src]
Generates a random u64
in the given range.
Panics if the range is empty.
pub fn u128(&self, range: impl RangeBounds<u128>) -> u128
[src]
Generates a random u128
in the given range.
Panics if the range is empty.
pub fn usize(&self, range: impl RangeBounds<usize>) -> usize
[src]
Generates a random usize
in the given range.
Panics if the range is empty.
pub fn uppercase(&self) -> char
[src]
Generates a random char
in range A-Z.
Trait Implementations
impl Clone for Rng
[src]
fn clone(&self) -> Rng
[src]
Clones the generator by deterministically deriving a new generator based on the initial seed.
Example
// Seed two generators equally, and clone both of them. let base1 = fastrand::Rng::new(); base1.seed(0x4d595df4d0f33173); base1.bool(); // Use the generator once. let base2 = fastrand::Rng::new(); base2.seed(0x4d595df4d0f33173); base2.bool(); // Use the generator once. let rng1 = base1.clone(); let rng2 = base2.clone(); assert_eq!(rng1.u64(..), rng2.u64(..), "the cloned generators are identical");
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Rng
[src]
impl Default for Rng
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Rng
impl Send for Rng
impl !Sync for Rng
impl Unpin for Rng
impl UnwindSafe for Rng
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut 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.
pub 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>,