Skip to content

Commit 3b06ad0

Browse files
committed
Deprecate Rng::gen_weighted_bool
1 parent b46f8b1 commit 3b06ad0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,17 @@ pub trait Rng: RngCore {
518518

519519
/// Return a bool with a 1 in n chance of true
520520
///
521+
/// # Deprecated
522+
/// Examples of what to replace `rng.gen_weighted_bool(3)` with
523+
/// (from fastest to slowest):
524+
/// ```
525+
/// # use rand::{thread_rng, Rng};
526+
/// # let mut rng = thread_rng();
527+
/// rng.gen::<u32>() < std::u32::MAX / 3;
528+
/// rng.gen::<f32>() < (1.0f32 / 3.0);
529+
/// rng.gen_range(0, 3) < 1;
530+
/// ```
531+
///
521532
/// # Example
522533
///
523534
/// ```rust
@@ -532,6 +543,7 @@ pub trait Rng: RngCore {
532543
/// // First meaningful use of `gen_weighted_bool`.
533544
/// println!("{}", rng.gen_weighted_bool(3));
534545
/// ```
546+
#[deprecated(since="0.5.0", note="use gen_range(0, n) < 1 instead")]
535547
fn gen_weighted_bool(&mut self, n: u32) -> bool {
536548
// Short-circuit after `n <= 1` to avoid panic in `gen_range`
537549
n <= 1 || self.gen_range(0, n) == 0
@@ -1076,6 +1088,7 @@ mod test {
10761088
}
10771089

10781090
#[test]
1091+
#[allow(deprecated)]
10791092
fn test_gen_weighted_bool() {
10801093
let mut r = rng(104);
10811094
assert_eq!(r.gen_weighted_bool(0), true);

0 commit comments

Comments
 (0)