Skip to content

Commit 269f3fd

Browse files
committed
Deprecate Rng::gen_weighted_bool
1 parent 2e8beaf commit 269f3fd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ pub trait Rng: RngCore {
521521
/// # Example
522522
///
523523
/// ```rust
524+
/// #[allow(deprecated)]
524525
/// use rand::{thread_rng, Rng};
525526
///
526527
/// let mut rng = thread_rng();
@@ -532,6 +533,7 @@ pub trait Rng: RngCore {
532533
/// // First meaningful use of `gen_weighted_bool`.
533534
/// println!("{}", rng.gen_weighted_bool(3));
534535
/// ```
536+
#[deprecated(since="0.5.0", note="use gen_bool instead")]
535537
fn gen_weighted_bool(&mut self, n: u32) -> bool {
536538
// Short-circuit after `n <= 1` to avoid panic in `gen_range`
537539
n <= 1 || self.gen_range(0, n) == 0
@@ -551,7 +553,7 @@ pub trait Rng: RngCore {
551553
assert!(p >= 0.0 && p <= 1.0);
552554
// If `p` is constant, this will be evaluated at compile-time.
553555
let p_int = (p * core::u32::MAX as f64) as u32;
554-
p_int > self.gen()
556+
self.gen::<u32>() <= p_int
555557
}
556558

557559
/// Return an iterator of random characters from the set A-Z,a-z,0-9.
@@ -1093,6 +1095,7 @@ mod test {
10931095
}
10941096

10951097
#[test]
1098+
#[allow(deprecated)]
10961099
fn test_gen_weighted_bool() {
10971100
let mut r = rng(104);
10981101
assert_eq!(r.gen_weighted_bool(0), true);

0 commit comments

Comments
 (0)