Skip to content

Commit 2d5948d

Browse files
authored
rand::distributions -> distr; split uniform module (#1470)
1 parent 605476c commit 2d5948d

40 files changed

+2012
-1918
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1818
- Enable feature `small_rng` by default (#1455)
1919
- Allow `UniformFloat::new` samples and `UniformFloat::sample_single` to yield `high` (#1462)
2020
- Fix portability of `rand::distributions::Slice` (#1469)
21+
- Rename `rand::distributions` to `rand::distr` (#1470)
2122

2223
## [0.9.0-alpha.1] - 2024-03-18
2324
- Add the `Slice::num_choices` method to the Slice distribution (#1402)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A Rust library for random number generation, featuring:
1717
([see the book](https://rust-random.github.io/book/crates.html))
1818
- Fast implementations of the best-in-class [cryptographic](https://rust-random.github.io/book/guide-rngs.html#cryptographically-secure-pseudo-random-number-generators-csprngs) and
1919
[non-cryptographic](https://rust-random.github.io/book/guide-rngs.html#basic-pseudo-random-number-generators-prngs) generators
20-
- A flexible [`distributions`](https://docs.rs/rand/*/rand/distributions/index.html) module
20+
- A flexible [`distributions`](https://docs.rs/rand/*/rand/distr/index.html) module
2121
- Samplers for a large number of random number distributions via our own
2222
[`rand_distr`](https://docs.rs/rand_distr) and via
2323
the [`statrs`](https://docs.rs/statrs/0.13.0/statrs/)

benches/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ criterion = "0.5"
1515
criterion-cycles-per-byte = "0.6"
1616

1717
[[bench]]
18-
name = "distributions"
19-
path = "src/distributions.rs"
18+
name = "distr"
19+
path = "src/distr.rs"
2020
harness = false
2121

2222
[[bench]]

benches/benches/base_distributions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ extern crate test;
1616

1717
const RAND_BENCH_N: u64 = 1000;
1818

19-
use rand::distributions::{Alphanumeric, Open01, OpenClosed01, Standard, Uniform};
20-
use rand::distributions::uniform::{UniformInt, UniformSampler};
19+
use rand::distr::{Alphanumeric, Open01, OpenClosed01, Standard, Uniform};
20+
use rand::distr::uniform::{UniformInt, UniformSampler};
2121
use core::mem::size_of;
2222
use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8};
2323
use core::time::Duration;
@@ -253,7 +253,7 @@ gen_range_float!(gen_range_f32, f32, -20000.0f32, 100000.0);
253253
gen_range_float!(gen_range_f64, f64, 123.456f64, 7890.12);
254254

255255

256-
// In src/distributions/uniform.rs, we say:
256+
// In src/distr/uniform.rs, we say:
257257
// Implementation of [`uniform_single`] is optional, and is only useful when
258258
// the implementation can be faster than `Self::new(low, high).sample(rng)`.
259259

benches/benches/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const RAND_BENCH_N: u64 = 1000;
1414

1515
use test::Bencher;
1616

17-
use rand::distributions::{Bernoulli, Distribution, Standard};
17+
use rand::distr::{Bernoulli, Distribution, Standard};
1818
use rand::prelude::*;
1919
use rand_pcg::{Pcg32, Pcg64Mcg};
2020

benches/benches/weighted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
extern crate test;
1212

13-
use rand::distributions::WeightedIndex;
13+
use rand::distr::WeightedIndex;
1414
use rand::Rng;
1515
use test::Bencher;
1616

File renamed without changes.

benches/src/uniform.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
use core::time::Duration;
1212
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
13-
use rand::distributions::uniform::{SampleRange, Uniform};
13+
use rand::distr::uniform::{SampleRange, Uniform};
1414
use rand::prelude::*;
1515
use rand_chacha::ChaCha8Rng;
1616
use rand_pcg::{Pcg32, Pcg64};

benches/src/uniform_float.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use core::time::Duration;
1616
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
17-
use rand::distributions::uniform::{SampleUniform, Uniform, UniformSampler};
17+
use rand::distr::uniform::{SampleUniform, Uniform, UniformSampler};
1818
use rand::prelude::*;
1919
use rand_chacha::ChaCha8Rng;
2020
use rand_pcg::{Pcg32, Pcg64};

examples/monte-carlo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! We can use the above fact to estimate the value of π: pick many points in
2424
//! the square at random, calculate the fraction that fall within the circle,
2525
//! and multiply this fraction by 4.
26-
use rand::distributions::{Distribution, Uniform};
26+
use rand::distr::{Distribution, Uniform};
2727

2828
fn main() {
2929
let range = Uniform::new(-1.0f64, 1.0).unwrap();

examples/monty-hall.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//!
2727
//! [Monty Hall Problem]: https://en.wikipedia.org/wiki/Monty_Hall_problem
2828
29-
use rand::distributions::{Distribution, Uniform};
29+
use rand::distr::{Distribution, Uniform};
3030
use rand::Rng;
3131

3232
struct SimulationResult {

examples/rayon-monte-carlo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! over BATCH_SIZE trials. Manually batching also turns out to be faster
3939
//! for the nondeterministic version of this program as well.
4040
41-
use rand::distributions::{Distribution, Uniform};
41+
use rand::distr::{Distribution, Uniform};
4242
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
4343
use rayon::prelude::*;
4444

rand_distr/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Implements a full suite of random number distribution sampling routines.
1010

11-
This crate is a superset of the [rand::distributions] module, including support
11+
This crate is a superset of the [rand::distr] module, including support
1212
for sampling from Beta, Binomial, Cauchy, ChiSquared, Dirichlet, Exponential,
1313
FisherF, Gamma, Geometric, Hypergeometric, InverseGaussian, LogNormal, Normal,
1414
Pareto, PERT, Poisson, StudentT, Triangular and Weibull distributions. Sampling
@@ -46,7 +46,7 @@ can be enabled. (Note that any other crate depending on `num-traits` with the
4646

4747

4848
[statrs]: https://github.com/boxtown/statrs
49-
[rand::distributions]: https://rust-random.github.io/rand/rand/distributions/index.html
49+
[rand::distr]: https://rust-random.github.io/rand/rand/distr/index.html
5050

5151
## License
5252

rand_distr/src/hypergeometric.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::Distribution;
44
use core::fmt;
55
#[allow(unused_imports)]
66
use num_traits::Float;
7-
use rand::distributions::uniform::Uniform;
7+
use rand::distr::uniform::Uniform;
88
use rand::Rng;
99

1010
#[derive(Clone, Copy, Debug, PartialEq)]

rand_distr/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
//!
2828
//! ## Re-exports
2929
//!
30-
//! This crate is a super-set of the [`rand::distributions`] module. See the
31-
//! [`rand::distributions`] module documentation for an overview of the core
30+
//! This crate is a super-set of the [`rand::distr`] module. See the
31+
//! [`rand::distr`] module documentation for an overview of the core
3232
//! [`Distribution`] trait and implementations.
3333
//!
3434
//! The following are re-exported:
@@ -93,7 +93,7 @@ extern crate std;
9393
#[allow(unused)]
9494
use rand::Rng;
9595

96-
pub use rand::distributions::{
96+
pub use rand::distr::{
9797
uniform, Alphanumeric, Bernoulli, BernoulliError, DistIter, Distribution, Open01, OpenClosed01,
9898
Standard, Uniform,
9999
};
@@ -129,7 +129,7 @@ pub use self::weibull::{Error as WeibullError, Weibull};
129129
pub use self::zeta::{Error as ZetaError, Zeta};
130130
pub use self::zipf::{Error as ZipfError, Zipf};
131131
#[cfg(feature = "alloc")]
132-
pub use rand::distributions::{WeightError, WeightedIndex};
132+
pub use rand::distr::{WeightError, WeightedIndex};
133133
pub use student_t::StudentT;
134134
#[cfg(feature = "alloc")]
135135
pub use weighted_alias::WeightedAliasIndex;

rand_distr/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
use crate::ziggurat_tables;
1212
use num_traits::Float;
13-
use rand::distributions::hidden_export::IntoFloat;
13+
use rand::distr::hidden_export::IntoFloat;
1414
use rand::Rng;
1515

1616
/// Calculates ln(gamma(x)) (natural logarithm of the gamma

rand_distr/src/weighted_tree.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use core::ops::SubAssign;
1414
use super::WeightError;
1515
use crate::Distribution;
1616
use alloc::vec::Vec;
17-
use rand::distributions::uniform::{SampleBorrow, SampleUniform};
18-
use rand::distributions::Weight;
17+
use rand::distr::uniform::{SampleBorrow, SampleUniform};
18+
use rand::distr::Weight;
1919
use rand::Rng;
2020
#[cfg(feature = "serde1")]
2121
use serde::{Deserialize, Serialize};
@@ -30,7 +30,7 @@ use serde::{Deserialize, Serialize};
3030
///
3131
/// # Key differences
3232
///
33-
/// The main distinction between [`WeightedTreeIndex<W>`] and [`rand::distributions::WeightedIndex<W>`]
33+
/// The main distinction between [`WeightedTreeIndex<W>`] and [`rand::distr::WeightedIndex<W>`]
3434
/// lies in the internal representation of weights. In [`WeightedTreeIndex<W>`],
3535
/// weights are structured as a tree, which is optimized for frequent updates of the weights.
3636
///

rand_distr/src/zeta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use crate::{Distribution, Standard};
1212
use core::fmt;
1313
use num_traits::Float;
14-
use rand::{distributions::OpenClosed01, Rng};
14+
use rand::{distr::OpenClosed01, Rng};
1515

1616
/// The [Zeta distribution](https://en.wikipedia.org/wiki/Zeta_distribution) `Zeta(s)`.
1717
///

src/distributions/bernoulli.rs renamed to src/distr/bernoulli.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
//! The Bernoulli distribution `Bernoulli(p)`.
1010
11-
use crate::distributions::Distribution;
11+
use crate::distr::Distribution;
1212
use crate::Rng;
1313
use core::fmt;
1414

@@ -31,7 +31,7 @@ use serde::{Deserialize, Serialize};
3131
/// # Example
3232
///
3333
/// ```rust
34-
/// use rand::distributions::{Bernoulli, Distribution};
34+
/// use rand::distr::{Bernoulli, Distribution};
3535
///
3636
/// let d = Bernoulli::new(0.3).unwrap();
3737
/// let v = d.sample(&mut rand::thread_rng());
@@ -153,7 +153,7 @@ impl Distribution<bool> for Bernoulli {
153153
#[cfg(test)]
154154
mod test {
155155
use super::Bernoulli;
156-
use crate::distributions::Distribution;
156+
use crate::distr::Distribution;
157157
use crate::Rng;
158158

159159
#[test]

src/distributions/distribution.rs renamed to src/distr/distribution.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub trait Distribution<T> {
4949
///
5050
/// ```
5151
/// use rand::thread_rng;
52-
/// use rand::distributions::{Distribution, Alphanumeric, Uniform, Standard};
52+
/// use rand::distr::{Distribution, Alphanumeric, Uniform, Standard};
5353
///
5454
/// let mut rng = thread_rng();
5555
///
@@ -89,7 +89,7 @@ pub trait Distribution<T> {
8989
///
9090
/// ```
9191
/// use rand::thread_rng;
92-
/// use rand::distributions::{Distribution, Uniform};
92+
/// use rand::distr::{Distribution, Uniform};
9393
///
9494
/// let mut rng = thread_rng();
9595
///
@@ -201,12 +201,12 @@ pub trait DistString {
201201

202202
#[cfg(test)]
203203
mod tests {
204-
use crate::distributions::{Distribution, Uniform};
204+
use crate::distr::{Distribution, Uniform};
205205
use crate::Rng;
206206

207207
#[test]
208208
fn test_distributions_iter() {
209-
use crate::distributions::Open01;
209+
use crate::distr::Open01;
210210
let mut rng = crate::test::rng(210);
211211
let distr = Open01;
212212
let mut iter = Distribution::<f32>::sample_iter(distr, &mut rng);
@@ -248,7 +248,7 @@ mod tests {
248248
#[test]
249249
#[cfg(feature = "alloc")]
250250
fn test_dist_string() {
251-
use crate::distributions::{Alphanumeric, DistString, Standard};
251+
use crate::distr::{Alphanumeric, DistString, Standard};
252252
use core::str;
253253
let mut rng = crate::test::rng(213);
254254

src/distributions/float.rs renamed to src/distr/float.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
//! Basic floating-point number distributions
1010
11-
use crate::distributions::utils::{FloatAsSIMD, FloatSIMDUtils, IntAsSIMD};
12-
use crate::distributions::{Distribution, Standard};
11+
use crate::distr::utils::{FloatAsSIMD, FloatSIMDUtils, IntAsSIMD};
12+
use crate::distr::{Distribution, Standard};
1313
use crate::Rng;
1414
use core::mem;
1515
#[cfg(feature = "simd_support")]
@@ -33,15 +33,15 @@ use serde::{Deserialize, Serialize};
3333
/// # Example
3434
/// ```
3535
/// use rand::{thread_rng, Rng};
36-
/// use rand::distributions::OpenClosed01;
36+
/// use rand::distr::OpenClosed01;
3737
///
3838
/// let val: f32 = thread_rng().sample(OpenClosed01);
3939
/// println!("f32 from (0, 1): {}", val);
4040
/// ```
4141
///
42-
/// [`Standard`]: crate::distributions::Standard
43-
/// [`Open01`]: crate::distributions::Open01
44-
/// [`Uniform`]: crate::distributions::uniform::Uniform
42+
/// [`Standard`]: crate::distr::Standard
43+
/// [`Open01`]: crate::distr::Open01
44+
/// [`Uniform`]: crate::distr::uniform::Uniform
4545
#[derive(Clone, Copy, Debug)]
4646
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
4747
pub struct OpenClosed01;
@@ -60,15 +60,15 @@ pub struct OpenClosed01;
6060
/// # Example
6161
/// ```
6262
/// use rand::{thread_rng, Rng};
63-
/// use rand::distributions::Open01;
63+
/// use rand::distr::Open01;
6464
///
6565
/// let val: f32 = thread_rng().sample(Open01);
6666
/// println!("f32 from (0, 1): {}", val);
6767
/// ```
6868
///
69-
/// [`Standard`]: crate::distributions::Standard
70-
/// [`OpenClosed01`]: crate::distributions::OpenClosed01
71-
/// [`Uniform`]: crate::distributions::uniform::Uniform
69+
/// [`Standard`]: crate::distr::Standard
70+
/// [`OpenClosed01`]: crate::distr::OpenClosed01
71+
/// [`Uniform`]: crate::distr::uniform::Uniform
7272
#[derive(Clone, Copy, Debug)]
7373
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
7474
pub struct Open01;

src/distributions/integer.rs renamed to src/distr/integer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
//! The implementations of the `Standard` distribution for integer types.
1010
11-
use crate::distributions::{Distribution, Standard};
11+
use crate::distr::{Distribution, Standard};
1212
use crate::Rng;
1313
#[cfg(all(target_arch = "x86", feature = "simd_support"))]
1414
use core::arch::x86::__m512i;

src/distributions/mod.rs renamed to src/distr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ use crate::Rng;
172172
/// ```
173173
/// # #![allow(dead_code)]
174174
/// use rand::Rng;
175-
/// use rand::distributions::{Distribution, Standard};
175+
/// use rand::distr::{Distribution, Standard};
176176
///
177177
/// struct MyF32 {
178178
/// x: f32,
@@ -188,7 +188,7 @@ use crate::Rng;
188188
/// ## Example usage
189189
/// ```
190190
/// use rand::prelude::*;
191-
/// use rand::distributions::Standard;
191+
/// use rand::distr::Standard;
192192
///
193193
/// let val: f32 = StdRng::from_os_rng().sample(Standard);
194194
/// println!("f32 from [0, 1): {}", val);

src/distributions/other.rs renamed to src/distr/other.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use core::char;
1414
use core::num::Wrapping;
1515

1616
#[cfg(feature = "alloc")]
17-
use crate::distributions::DistString;
18-
use crate::distributions::{Distribution, Standard, Uniform};
17+
use crate::distr::DistString;
18+
use crate::distr::{Distribution, Standard, Uniform};
1919
use crate::Rng;
2020

2121
use core::mem::{self, MaybeUninit};
@@ -35,7 +35,7 @@ use serde::{Deserialize, Serialize};
3535
///
3636
/// ```
3737
/// use rand::{Rng, thread_rng};
38-
/// use rand::distributions::Alphanumeric;
38+
/// use rand::distr::Alphanumeric;
3939
///
4040
/// let mut rng = thread_rng();
4141
/// let chars: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
@@ -45,7 +45,7 @@ use serde::{Deserialize, Serialize};
4545
/// The [`DistString`] trait provides an easier method of generating
4646
/// a random `String`, and offers more efficient allocation:
4747
/// ```
48-
/// use rand::distributions::{Alphanumeric, DistString};
48+
/// use rand::distr::{Alphanumeric, DistString};
4949
/// let string = Alphanumeric.sample_string(&mut rand::thread_rng(), 16);
5050
/// println!("Random string: {}", string);
5151
/// ```

0 commit comments

Comments
 (0)