pub struct PyRandom { /* private fields */ }Expand description
A CPython-compatible random.Random instance: MT19937 state plus the pure-Python wrapper
logic (_randbelow, sample, shuffle) from Lib/random.py.
Implementations§
Source§impl PyRandom
impl PyRandom
pub fn new(seed: u64) -> Self
Sourcepub fn randbelow(&mut self, n: u64) -> u64
pub fn randbelow(&mut self, n: u64) -> u64
Random._randbelow_with_getrandbits: rejection-sampled getrandbits.
Sourcepub fn sample_indices(&mut self, n: usize, k: usize) -> Vec<usize>
pub fn sample_indices(&mut self, n: usize, k: usize) -> Vec<usize>
Random.sample(range(n), k) restricted to integer populations 0..n (the only case
needed here — feature/class/row indices), returning the sampled indices in draw order.
Auto Trait Implementations§
impl Freeze for PyRandom
impl RefUnwindSafe for PyRandom
impl Send for PyRandom
impl Sync for PyRandom
impl Unpin for PyRandom
impl UnsafeUnpin for PyRandom
impl UnwindSafe for PyRandom
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
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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