pub struct Rng(_);
Expand description
A random number generator.
Implementations
sourceimpl Rng
impl Rng
sourcepub fn with_seed(seed: u64) -> Self
pub fn with_seed(seed: u64) -> Self
Creates a new random number generator with the initial seed.
sourcepub fn alphabetic(&self) -> char
pub fn alphabetic(&self) -> char
Generates a random char
in ranges a-z and A-Z.
sourcepub fn alphanumeric(&self) -> char
pub fn alphanumeric(&self) -> char
Generates a random char
in ranges a-z, A-Z and 0-9.
sourcepub fn digit(&self, base: u32) -> char
pub fn digit(&self, base: u32) -> char
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.
sourcepub fn i8(&self, range: impl RangeBounds<i8>) -> i8
pub fn i8(&self, range: impl RangeBounds<i8>) -> i8
Generates a random i8
in the given range.
Panics if the range is empty.
sourcepub fn i16(&self, range: impl RangeBounds<i16>) -> i16
pub fn i16(&self, range: impl RangeBounds<i16>) -> i16
Generates a random i16
in the given range.
Panics if the range is empty.
sourcepub fn i32(&self, range: impl RangeBounds<i32>) -> i32
pub fn i32(&self, range: impl RangeBounds<i32>) -> i32
Generates a random i32
in the given range.
Panics if the range is empty.
sourcepub fn i64(&self, range: impl RangeBounds<i64>) -> i64
pub fn i64(&self, range: impl RangeBounds<i64>) -> i64
Generates a random i64
in the given range.
Panics if the range is empty.
sourcepub fn i128(&self, range: impl RangeBounds<i128>) -> i128
pub fn i128(&self, range: impl RangeBounds<i128>) -> i128
Generates a random i128
in the given range.
Panics if the range is empty.
sourcepub fn isize(&self, range: impl RangeBounds<isize>) -> isize
pub fn isize(&self, range: impl RangeBounds<isize>) -> isize
Generates a random isize
in the given range.
Panics if the range is empty.
sourcepub fn u8(&self, range: impl RangeBounds<u8>) -> u8
pub fn u8(&self, range: impl RangeBounds<u8>) -> u8
Generates a random u8
in the given range.
Panics if the range is empty.
sourcepub fn u16(&self, range: impl RangeBounds<u16>) -> u16
pub fn u16(&self, range: impl RangeBounds<u16>) -> u16
Generates a random u16
in the given range.
Panics if the range is empty.
sourcepub fn u32(&self, range: impl RangeBounds<u32>) -> u32
pub fn u32(&self, range: impl RangeBounds<u32>) -> u32
Generates a random u32
in the given range.
Panics if the range is empty.
sourcepub fn u64(&self, range: impl RangeBounds<u64>) -> u64
pub fn u64(&self, range: impl RangeBounds<u64>) -> u64
Generates a random u64
in the given range.
Panics if the range is empty.
sourcepub fn u128(&self, range: impl RangeBounds<u128>) -> u128
pub fn u128(&self, range: impl RangeBounds<u128>) -> u128
Generates a random u128
in the given range.
Panics if the range is empty.
sourcepub fn usize(&self, range: impl RangeBounds<usize>) -> usize
pub fn usize(&self, range: impl RangeBounds<usize>) -> usize
Generates a random usize
in the given range.
Panics if the range is empty.
sourcepub fn char(&self, range: impl RangeBounds<char>) -> char
pub fn char(&self, range: impl RangeBounds<char>) -> char
Generates a random char
in the given range.
Panics if the range is empty.
Trait Implementations
sourceimpl Clone for Rng
impl Clone for Rng
sourcefn clone(&self) -> Rng
fn clone(&self) -> Rng
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");
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Eq for Rng
impl StructuralEq for Rng
impl StructuralPartialEq for Rng
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more