pub struct Xorshift { /* private fields */ }Expand description
A random number generator based on 32bits state.
The genrator can be shared and generate random numbers across workers but it doesn’t provide synchronization.
§Reference
Implementations§
Source§impl Xorshift
impl Xorshift
Sourcepub const fn new(seed: NonZeroU32) -> Self
pub const fn new(seed: NonZeroU32) -> Self
Sourcepub fn next(&self) -> u32
pub fn next(&self) -> u32
Generates next random number from the current state.
You can call this method on multiple workers at the same time. The generator is using atomic variable under the hood, so that it’s guaranteed to generate a random number from different states.
§Examples
use my_ecs::ds::Xorshift;
use std::{num::NonZeroU32, collections::HashSet};
let gen = Xorshift::new(NonZeroU32::MIN);
let mut randoms = HashSet::new();
for _ in 0..100 {
let is_new = randoms.insert(gen.next());
assert!(is_new);
}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Xorshift
impl RefUnwindSafe for Xorshift
impl Send for Xorshift
impl Sync for Xorshift
impl Unpin for Xorshift
impl UnwindSafe for Xorshift
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
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