@@ -518,9 +518,21 @@ pub trait Rng: RngCore {
518
518
519
519
/// Return a bool with a 1 in n chance of true
520
520
///
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
+ ///
521
532
/// # Example
522
533
///
523
534
/// ```rust
535
+ /// #[allow(deprecated)]
524
536
/// use rand::{thread_rng, Rng};
525
537
///
526
538
/// let mut rng = thread_rng();
@@ -532,6 +544,7 @@ pub trait Rng: RngCore {
532
544
/// // First meaningful use of `gen_weighted_bool`.
533
545
/// println!("{}", rng.gen_weighted_bool(3));
534
546
/// ```
547
+ #[ deprecated( since="0.5.0" , note="use gen_range(0, n) < 1 instead" ) ]
535
548
fn gen_weighted_bool ( & mut self , n : u32 ) -> bool {
536
549
// Short-circuit after `n <= 1` to avoid panic in `gen_range`
537
550
n <= 1 || self . gen_range ( 0 , n) == 0
@@ -1076,6 +1089,7 @@ mod test {
1076
1089
}
1077
1090
1078
1091
#[ test]
1092
+ #[ allow( deprecated) ]
1079
1093
fn test_gen_weighted_bool ( ) {
1080
1094
let mut r = rng ( 104 ) ;
1081
1095
assert_eq ! ( r. gen_weighted_bool( 0 ) , true ) ;
0 commit comments