Lines Matching +full:is +full:- +full:generator +full:- +full:fn
1 //! A simple and fast random number generator.
3 //! The implementation uses [Wyrand](https://github.com/wangyi-fudan/wyhash), a simple and fast
4 //! generator but **not** cryptographically secure.
48 //! To get reproducible results on every run, initialize the generator with a seed:
58 //! To be more efficient, create a new [`Rng`] instance instead of using the thread-local
59 //! generator:
83 /// A random number generator.
89 fn default() -> Rng { in default()
95 /// Clones the generator by deterministically deriving a new generator based on the initial
104 /// base1.bool(); // Use the generator once.
108 /// base2.bool(); // Use the generator once.
115 fn clone(&self) -> Rng { in clone()
123 fn gen_u32(&self) -> u32 { in gen_u32()
129 fn gen_u64(&self) -> u64 { in gen_u64()
138 fn gen_u128(&self) -> u128 { in gen_u128()
144 fn gen_mod_u32(&self, n: u32) -> u32 { in gen_mod_u32()
145 // Adapted from: https://lemire.me/blog/2016/06/30/fast-random-shuffling/ in gen_mod_u32()
162 fn gen_mod_u64(&self, n: u64) -> u64 { in gen_mod_u64()
163 // Adapted from: https://lemire.me/blog/2016/06/30/fast-random-shuffling/ in gen_mod_u64()
180 fn gen_mod_u128(&self, n: u128) -> u128 { in gen_mod_u128()
181 // Adapted from: https://lemire.me/blog/2016/06/30/fast-random-shuffling/ in gen_mod_u128()
209 fn mul_high_u32(a: u32, b: u32) -> u32 { in mul_high_u32()
215 fn mul_high_u64(a: u64, b: u64) -> u64 { in mul_high_u64()
221 fn mul_high_u128(a: u128, b: u128) -> u128 { in mul_high_u128()
236 /// Panics if the range is empty.
238 pub fn $t(&self, range: impl RangeBounds<$t>) -> $t {
274 /// Creates a new random number generator.
276 pub fn new() -> Rng { in new()
283 /// Creates a new random number generator with the initial seed.
285 …reates a new instance of `Rng`; if you want to initialize the thread-local generator, use `fastran…
286 pub fn with_seed(seed: u64) -> Self { in with_seed()
293 /// Generates a random `char` in ranges a-z and A-Z.
295 pub fn alphabetic(&self) -> char { in alphabetic()
302 /// Generates a random `char` in ranges a-z, A-Z and 0-9.
304 pub fn alphanumeric(&self) -> char { in alphanumeric()
313 pub fn bool(&self) -> bool { in bool()
319 /// Digits are represented by `char`s in ranges 0-9 and a-z.
321 /// Panics if the base is zero or greater than 36.
323 pub fn digit(&self, base: u32) -> char { in digit()
334 (b'a' + num - 10) as char in digit()
339 pub fn f32(&self) -> f32 { in f32()
341 let f = std::f32::MANTISSA_DIGITS - 1; in f32()
342 f32::from_bits((1 << (b - 2)) - (1 << f) + (self.u32(..) >> (b - f))) - 1.0 in f32()
346 pub fn f64(&self) -> f64 { in f64()
348 let f = std::f64::MANTISSA_DIGITS - 1; in f64()
349 f64::from_bits((1 << (b - 2)) - (1 << f) + (self.u64(..) >> (b - f))) - 1.0 in f64()
417 /// Generates a random `char` in range a-z.
419 pub fn lowercase(&self) -> char { in lowercase()
426 /// Initializes this generator with the given seed.
428 pub fn seed(&self, seed: u64) { in seed()
432 /// Gives back **current** seed that is being held by this generator.
434 pub fn get_seed(&self) -> u64 { in get_seed()
440 pub fn shuffle<T>(&self, slice: &mut [T]) { in shuffle()
448 pub fn fill(&self, slice: &mut [u8]) { in fill()
543 /// Generates a random `char` in range A-Z.
545 pub fn uppercase(&self) -> char { in uppercase()
554 /// Panics if the range is empty.
556 pub fn char(&self, range: impl RangeBounds<char>) -> char { in char()
574 let scalar = if x as u32 == surrogate_start - 1 { in char()
588 surrogate_start - 1 in char()
605 let range = high as u32 - low as u32 - gap; in char()
614 /// Initializes the thread-local generator with the given seed.
616 pub fn seed(seed: u64) { in seed()
620 /// Gives back **current** seed that is being held by the thread-local generator.
622 pub fn get_seed() -> u64 { in get_seed()
628 pub fn bool() -> bool { in bool()
632 /// Generates a random `char` in ranges a-z and A-Z.
634 pub fn alphabetic() -> char { in alphabetic()
638 /// Generates a random `char` in ranges a-z, A-Z and 0-9.
640 pub fn alphanumeric() -> char { in alphanumeric()
644 /// Generates a random `char` in range a-z.
646 pub fn lowercase() -> char { in lowercase()
650 /// Generates a random `char` in range A-Z.
652 pub fn uppercase() -> char { in uppercase()
658 /// Digits are represented by `char`s in ranges 0-9 and a-z.
660 /// Panics if the base is zero or greater than 36.
662 pub fn digit(base: u32) -> char { in digit()
668 pub fn shuffle<T>(slice: &mut [T]) { in shuffle()
676 /// Panics if the range is empty.
678 pub fn $t(range: impl RangeBounds<$t>) -> $t {
699 pub fn f32() -> f32 { in f32()
704 pub fn f64() -> f64 { in f64()