13
13
//! Distributions are stateless (i.e. immutable) objects controlling the
14
14
//! production of values of some type `T` from a presumed uniform randomness
15
15
//! source. These objects may have internal parameters set at contruction time
16
- //! (e.g. [`Range `], which has configurable bounds) or may have no internal
16
+ //! (e.g. [`Uniform `], which has configurable bounds) or may have no internal
17
17
//! parameters (e.g. [`Standard`]).
18
18
//!
19
19
//! All distributions support the [`Distribution`] trait, and support usage
20
20
//! via `distr.sample(&mut rng)` as well as via `rng.sample(distr)`.
21
21
//!
22
22
//! [`Distribution`]: trait.Distribution.html
23
- //! [`Range `]: range /struct.Range .html
23
+ //! [`Uniform `]: uniform /struct.Uniform .html
24
24
//! [`Standard`]: struct.Standard.html
25
25
26
26
use Rng ;
27
27
28
28
pub use self :: other:: Alphanumeric ;
29
- pub use self :: range:: Range ;
29
+ pub use self :: uniform:: Uniform ;
30
+ #[ deprecated( since="0.5.0" , note="use Uniform instead" ) ]
31
+ pub use self :: uniform:: Uniform as Range ;
30
32
#[ cfg( feature="std" ) ]
31
33
pub use self :: gamma:: { Gamma , ChiSquared , FisherF , StudentT } ;
32
34
#[ cfg( feature="std" ) ]
@@ -38,7 +40,7 @@ pub use self::poisson::Poisson;
38
40
#[ cfg( feature = "std" ) ]
39
41
pub use self :: binomial:: Binomial ;
40
42
41
- pub mod range ;
43
+ pub mod uniform ;
42
44
#[ cfg( feature="std" ) ]
43
45
pub mod gamma;
44
46
#[ cfg( feature="std" ) ]
@@ -80,6 +82,13 @@ pub trait IndependentSample<Support>: Sample<Support> {
80
82
fn ind_sample < R : Rng > ( & self , & mut R ) -> Support ;
81
83
}
82
84
85
+ /// DEPRECATED: Use `distributions::uniform` instead.
86
+ #[ deprecated( since="0.5.0" , note="use uniform instead" ) ]
87
+ pub mod range {
88
+ pub use distributions:: uniform:: Uniform as Range ;
89
+ pub use distributions:: uniform:: SampleUniform as SampleRange ;
90
+ }
91
+
83
92
#[ allow( deprecated) ]
84
93
mod impls {
85
94
use Rng ;
@@ -152,7 +161,7 @@ pub trait Distribution<T> {
152
161
///
153
162
/// ```rust
154
163
/// use rand::thread_rng;
155
- /// use rand::distributions::{Distribution, Alphanumeric, Range , Standard};
164
+ /// use rand::distributions::{Distribution, Alphanumeric, Uniform , Standard};
156
165
///
157
166
/// let mut rng = thread_rng();
158
167
///
@@ -163,7 +172,7 @@ pub trait Distribution<T> {
163
172
/// let s: String = Alphanumeric.sample_iter(&mut rng).take(7).collect();
164
173
///
165
174
/// // Dice-rolling:
166
- /// let die_range = Range ::new_inclusive(1, 6);
175
+ /// let die_range = Uniform ::new_inclusive(1, 6);
167
176
/// let mut roll_die = die_range.sample_iter(&mut rng);
168
177
/// while roll_die.next().unwrap() != 6 {
169
178
/// println!("Not a 6; rolling again!");
@@ -343,7 +352,7 @@ pub struct Weighted<T> {
343
352
#[ derive( Debug ) ]
344
353
pub struct WeightedChoice < ' a , T : ' a > {
345
354
items : & ' a mut [ Weighted < T > ] ,
346
- weight_range : Range < u32 > ,
355
+ weight_range : Uniform < u32 > ,
347
356
}
348
357
349
358
impl < ' a , T : Clone > WeightedChoice < ' a , T > {
@@ -378,7 +387,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
378
387
items,
379
388
// we're likely to be generating numbers in this range
380
389
// relatively often, so might as well cache it
381
- weight_range : Range :: new ( 0 , running_total)
390
+ weight_range : Uniform :: new ( 0 , running_total)
382
391
}
383
392
}
384
393
}
@@ -499,7 +508,7 @@ mod tests {
499
508
fn test_weighted_choice ( ) {
500
509
// this makes assumptions about the internal implementation of
501
510
// WeightedChoice. It may fail when the implementation in
502
- // `distributions::range::RangeInt changes.
511
+ // `distributions::uniform::UniformInt` changes.
503
512
504
513
macro_rules! t {
505
514
( $items: expr, $expected: expr) => { {
@@ -511,7 +520,7 @@ mod tests {
511
520
let expected = $expected;
512
521
513
522
// Use extremely large steps between the random numbers, because
514
- // we test with small ranges and RangeInt is designed to prefer
523
+ // we test with small ranges and `UniformInt` is designed to prefer
515
524
// the most significant bits.
516
525
let mut rng = StepRng :: new( 0 , !0 / ( total_weight as u64 ) ) ;
517
526
0 commit comments