pub struct Generator { /* private fields */ }Expand description
Pseudo-random number generator used across the tenferro workspace.
The CPU half uses an MT19937 engine seeded from a u64. CUDA execution
uses the same public Generator surface but advances an internal
seed/offset pair that device kernels consume through a Philox-style
counter-based scheme.
§Examples
use tenferro_device::Generator;
let mut generator = Generator::cpu(1234);
let sample = generator.sample_uniform_f64();
assert!(sample >= 0.0 && sample < 1.0);Implementations§
Source§impl Generator
impl Generator
Sourcepub fn cpu(seed: u64) -> Self
pub fn cpu(seed: u64) -> Self
Create a CPU generator from a seed.
§Examples
use tenferro_device::Generator;
let _generator = Generator::cpu(42);Sourcepub fn sample_uniform_f64(&mut self) -> f64
pub fn sample_uniform_f64(&mut self) -> f64
Draw a floating-point sample from the half-open interval [0, 1).
§Examples
use tenferro_device::Generator;
let mut generator = Generator::cpu(7);
let x = generator.sample_uniform_f64();
assert!(x >= 0.0 && x < 1.0);Sourcepub fn sample_standard_normal_f64(&mut self) -> f64
pub fn sample_standard_normal_f64(&mut self) -> f64
Draw a standard normal sample using Box-Muller sampling.
§Examples
use tenferro_device::Generator;
let mut generator = Generator::cpu(7);
let _z = generator.sample_standard_normal_f64();Sourcepub fn sample_integer_i32(&mut self, low: i32, high: i32) -> Result<i32>
pub fn sample_integer_i32(&mut self, low: i32, high: i32) -> Result<i32>
Draw an integer sample from the half-open interval [low, high).
§Errors
Returns Error::InvalidArgument if low >= high.
§Examples
use tenferro_device::Generator;
let mut generator = Generator::cpu(7);
let x = generator.sample_integer_i32(-3, 7).unwrap();
assert!((-3..7).contains(&x));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Generator
impl RefUnwindSafe for Generator
impl Send for Generator
impl Sync for Generator
impl Unpin for Generator
impl UnwindSafe for Generator
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