File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -518,6 +518,17 @@ 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
@@ -532,6 +543,7 @@ pub trait Rng: RngCore {
532
543
/// // First meaningful use of `gen_weighted_bool`.
533
544
/// println!("{}", rng.gen_weighted_bool(3));
534
545
/// ```
546
+ #[ deprecated( since="0.5.0" , note="use gen_range(0, n) < 1 instead" ) ]
535
547
fn gen_weighted_bool ( & mut self , n : u32 ) -> bool {
536
548
// Short-circuit after `n <= 1` to avoid panic in `gen_range`
537
549
n <= 1 || self . gen_range ( 0 , n) == 0
@@ -1076,6 +1088,7 @@ mod test {
1076
1088
}
1077
1089
1078
1090
#[ test]
1091
+ #[ allow( deprecated) ]
1079
1092
fn test_gen_weighted_bool ( ) {
1080
1093
let mut r = rng ( 104 ) ;
1081
1094
assert_eq ! ( r. gen_weighted_bool( 0 ) , true ) ;
You can’t perform that action at this time.
0 commit comments