We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ff72490 commit f03bf15Copy full SHA for f03bf15
src/lib.rs
@@ -537,6 +537,21 @@ pub trait Rng: RngCore {
537
n <= 1 || self.gen_range(0, n) == 0
538
}
539
540
+ /// Return a bool with a `p` probability of being true.
541
+ ///
542
+ /// # Example
543
544
+ /// ```rust
545
+ /// use rand::{thread_rng, Rng};
546
547
+ /// let mut rng = thread_rng();
548
+ /// println!("{}", rng.gen_bool(1.0 / 3.0));
549
+ /// ```
550
+ fn gen_bool(&mut self, p: f64) -> bool {
551
+ assert!(p >= 0.0 && p <= 1.0);
552
+ self.sample::<f64, _>(distributions::HighPrecision01) < p
553
+ }
554
+
555
/// Return an iterator of random characters from the set A-Z,a-z,0-9.
556
///
557
/// # Example
0 commit comments