Struct malachite_base::random::Seed
source · [−]Expand description
A type representing a random seed.
Fields
bytes: [u8; 32]
Implementations
sourceimpl Seed
impl Seed
sourcepub const fn from_bytes(bytes: [u8; 32]) -> Seed
pub const fn from_bytes(bytes: [u8; 32]) -> Seed
Creates a Seed
from a slice of 32 bytes.
Worst-case complexity
Constant time and additional memory.
Examples
use malachite_base::random::Seed;
Seed::from_bytes([10; 32]);
sourcepub fn get_rng(self) -> ChaCha20Rng
pub fn get_rng(self) -> ChaCha20Rng
Creates a PRNG from a slice of 32 bytes.
Worst-case complexity
Constant time and additional memory.
Examples
use malachite_base::random::EXAMPLE_SEED;
EXAMPLE_SEED.get_rng();
sourcepub fn next(self) -> Seed
pub fn next(self) -> Seed
Uniformly generates a random Seed
.
Worst-case complexity
Constant time and additional memory.
Examples
use malachite_base::random::Seed;
use malachite_base::random::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) -> Seed
pub fn fork(&self, key: &str) -> Seed
Generates a new Seed
from this seed. Passing different key
s will, with very high
probability, generate different seeds.
Worst-case complexity
Constant time and additional memory.
Examples
use malachite_base::random::Seed;
use malachite_base::random::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 StructuralEq for Seed
impl StructuralPartialEq for Seed
Auto Trait Implementations
impl RefUnwindSafe for Seed
impl Send for Seed
impl Sync for Seed
impl Unpin for Seed
impl UnwindSafe for Seed
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