pub struct Random { /* private fields */ }
Expand description
Random Generator
Implementationsยง
Sourceยงimpl Random
impl Random
Sourcepub fn new(seed: i64) -> Random
pub fn new(seed: i64) -> Random
Make a new random generator
Used default values for a, c and m
a: 16807
c: 0
m: 2147483647
ยงExample
// Import Lib
use micro_rand::Random;
// Make a new random generator with seed 1234
let mut r = Random::new(1234);
Sourcepub fn custom_new(seed: i64, a: i64, c: i64, m: i64) -> Random
pub fn custom_new(seed: i64, a: i64, c: i64, m: i64) -> Random
Make a new random generator with custom values for a, c and m
ยงExample
// Import Lib
use micro_rand::Random;
// Make a new, custom random generator
let mut r = Random::custom_new(1234, 86284, 2, 7263957720);
Sourcepub fn next_f64(&mut self) -> f64
pub fn next_f64(&mut self) -> f64
Geth the next float 64 from a generator
ยงExample
// Import Lib
use micro_rand::Random;
// Make a new, custom random generator
let mut r = Random::new(1234);
// Get the next float 64
let f = r.next_f64();
Sourcepub fn next_f32(&mut self) -> f32
pub fn next_f32(&mut self) -> f32
Geth the next float 32 from a generator
ยงExample
// Import Lib
use micro_rand::Random;
// Make a new, custom random generator
let mut r = Random::new(1234);
// Get the next float 32
let f = r.next_f32();
Sourcepub fn next_int_i64(&mut self, min: i64, max: i64) -> i64
pub fn next_int_i64(&mut self, min: i64, max: i64) -> i64
Geth the next i64 from a generator within a range
ยงExample
// Import Lib
use micro_rand::Random;
// Make a new, custom random generator
let mut r = Random::new(1234);
// Get a random i64 between 0 and 100
let f = r.next_int_i64(0, 100);
Sourcepub fn next_int_i32(&mut self, min: i32, max: i32) -> i32
pub fn next_int_i32(&mut self, min: i32, max: i32) -> i32
Geth the next i32 from a generator within a range
ยงExample
// Import Lib
use micro_rand::Random;
// Make a new, custom random generator
let mut r = Random::new(1234);
// Get a random i32 between 0 and 100
let f = r.next_int_i32(0, 100);
Auto Trait Implementationsยง
impl Freeze for Random
impl RefUnwindSafe for Random
impl Send for Random
impl Sync for Random
impl Unpin for Random
impl UnwindSafe for Random
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