@@ -521,6 +521,7 @@ pub trait Rng: RngCore {
521
521
/// # Example
522
522
///
523
523
/// ```rust
524
+ /// #[allow(deprecated)]
524
525
/// use rand::{thread_rng, Rng};
525
526
///
526
527
/// let mut rng = thread_rng();
@@ -532,6 +533,7 @@ pub trait Rng: RngCore {
532
533
/// // First meaningful use of `gen_weighted_bool`.
533
534
/// println!("{}", rng.gen_weighted_bool(3));
534
535
/// ```
536
+ #[ deprecated( since="0.5.0" , note="use gen_bool instead" ) ]
535
537
fn gen_weighted_bool ( & mut self , n : u32 ) -> bool {
536
538
// Short-circuit after `n <= 1` to avoid panic in `gen_range`
537
539
n <= 1 || self . gen_range ( 0 , n) == 0
@@ -551,7 +553,7 @@ pub trait Rng: RngCore {
551
553
assert ! ( p >= 0.0 && p <= 1.0 ) ;
552
554
// If `p` is constant, this will be evaluated at compile-time.
553
555
let p_int = ( p * core:: u32:: MAX as f64 ) as u32 ;
554
- p_int > self . gen ( )
556
+ self . gen :: < u32 > ( ) <= p_int
555
557
}
556
558
557
559
/// Return an iterator of random characters from the set A-Z,a-z,0-9.
@@ -1093,6 +1095,7 @@ mod test {
1093
1095
}
1094
1096
1095
1097
#[ test]
1098
+ #[ allow( deprecated) ]
1096
1099
fn test_gen_weighted_bool ( ) {
1097
1100
let mut r = rng ( 104 ) ;
1098
1101
assert_eq ! ( r. gen_weighted_bool( 0 ) , true ) ;
0 commit comments