pub struct Seed {
pub bytes: [u8; 32],
}Expand description
A type representing a random seed.
Fields§
§bytes: [u8; 32]Implementations§
Source§impl Seed
impl Seed
Sourcepub const fn from_bytes(bytes: [u8; 32]) -> Self
pub const fn from_bytes(bytes: [u8; 32]) -> Self
Sourcepub fn get_rng(self) -> ChaCha20Rng
pub fn get_rng(self) -> ChaCha20Rng
Sourcepub fn next(self) -> Self
pub fn next(self) -> Self
Uniformly generates a random Seed.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::random::{Seed, EXAMPLE_SEED};
assert_eq!(
EXAMPLE_SEED.next(),
Seed::from_bytes([
0x71, 0xef, 0x45, 0x6c, 0xe4, 0xd2, 0xa8, 0xa1, 0x57, 0x20, 0x6e, 0x53, 0xbc, 0x22,
0x59, 0xee, 0x5d, 0xc8, 0x95, 0x73, 0xbd, 0x95, 0xd9, 0xc9, 0x75, 0x92, 0x1f, 0x48,
0x97, 0xa9, 0xae, 0x21
])
);Sourcepub fn fork(&self, key: &str) -> Self
pub fn fork(&self, key: &str) -> Self
Generates a new Seed from this seed. Passing different keys will, with very high
probability, generate different seeds.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is key.len().
§Examples
use malachite_base::random::{Seed, EXAMPLE_SEED};
assert_eq!(
EXAMPLE_SEED.fork("first"),
Seed::from_bytes([
0x20, 0x18, 0x1, 0x3d, 0x96, 0x4d, 0x3e, 0x98, 0x10, 0x9d, 0x35, 0x75, 0x22, 0x89,
0xf7, 0xe9, 0xbe, 0x2f, 0x9c, 0x15, 0x95, 0x42, 0x1a, 0x79, 0x52, 0xf, 0x56, 0x9a,
0x7b, 0x8c, 0xd9, 0x34
])
);
assert_eq!(
EXAMPLE_SEED.fork("second"),
Seed::from_bytes([
0xe0, 0x36, 0x88, 0x58, 0x6d, 0x67, 0x33, 0xea, 0xf2, 0x1c, 0x88, 0xf9, 0xe3, 0xbd,
0x52, 0xc0, 0xe5, 0xad, 0x61, 0x81, 0x21, 0xd8, 0x2f, 0x8e, 0xcd, 0xf, 0x89, 0x9d,
0x32, 0xc5, 0x35, 0x83
])
);Trait Implementations§
impl Copy for Seed
impl Eq for Seed
impl StructuralPartialEq for Seed
Auto Trait Implementations§
impl Freeze for Seed
impl RefUnwindSafe for Seed
impl Send for Seed
impl Sync for Seed
impl Unpin for Seed
impl UnsafeUnpin for Seed
impl UnwindSafe for Seed
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more