Skip to content

Commit 3f984dd

Browse files
authored
Rename StandardStandardUniform (#1526)
Also remove impl for Option<T>
1 parent e85c923 commit 3f984dd

25 files changed

+212
-225
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
3030
- Rename `rand::thread_rng()` to `rand::rng()`, and remove from the prelude (#1506)
3131
- Remove `rand::random()` from the prelude (#1506)
3232
- Rename `Rng::gen_range` to `random_range`, `gen_bool` to `random_bool`, `gen_ratio` to `random_ratio` (#1505)
33+
- Rename `Standard` to `StandardUniform` (#1526)
34+
- Remove impl of `Distribution<Option<T>>` for `Standard` (#1526)
3335

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Rand is a set of crates supporting (pseudo-)random generators:
1616

1717
With broad support for random value generation and random processes:
1818

19-
- [`Standard`](https://docs.rs/rand/latest/rand/distributions/struct.Standard.html) random value sampling,
19+
- [`StandardUniform`](https://docs.rs/rand/latest/rand/distributions/struct.StandardUniform.html) random value sampling,
2020
[`Uniform`](https://docs.rs/rand/latest/rand/distributions/struct.Uniform.html)-ranged value sampling
2121
and [more](https://docs.rs/rand/latest/rand/distr/index.html)
2222
- Samplers for a large number of non-uniform random number distributions via our own

benches/benches/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! Generating/filling arrays and iterators of output
1010
1111
use criterion::{criterion_group, criterion_main, Criterion};
12-
use rand::distr::Standard;
12+
use rand::distr::StandardUniform;
1313
use rand::prelude::*;
1414
use rand_pcg::Pcg64Mcg;
1515

@@ -36,7 +36,7 @@ pub fn bench(c: &mut Criterion) {
3636
g.bench_function("u16_sample_iter", |b| {
3737
let mut rng = Pcg64Mcg::from_rng(&mut rand::rng());
3838
b.iter(|| {
39-
let v: Vec<u16> = Standard.sample_iter(&mut rng).take(512).collect();
39+
let v: Vec<u16> = StandardUniform.sample_iter(&mut rng).take(512).collect();
4040
v
4141
});
4242
});
@@ -70,7 +70,7 @@ pub fn bench(c: &mut Criterion) {
7070
g.bench_function("u64_sample_iter", |b| {
7171
let mut rng = Pcg64Mcg::from_rng(&mut rand::rng());
7272
b.iter(|| {
73-
let v: Vec<u64> = Standard.sample_iter(&mut rng).take(128).collect();
73+
let v: Vec<u64> = StandardUniform.sample_iter(&mut rng).take(128).collect();
7474
v
7575
});
7676
});

benches/benches/bool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn bench(c: &mut Criterion) {
2828

2929
g.bench_function("standard", |b| {
3030
let mut rng = Pcg32::from_rng(&mut rand::rng());
31-
b.iter(|| rng.sample::<bool, _>(rand::distr::Standard))
31+
b.iter(|| rng.sample::<bool, _>(rand::distr::StandardUniform))
3232
});
3333

3434
g.bench_function("const", |b| {

benches/benches/generators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub fn init_from_seed(c: &mut Criterion) {
171171

172172
fn bench<R: SeedableRng>(g: &mut BenchmarkGroup<WallTime>, name: &str)
173173
where
174-
rand::distr::Standard: Distribution<<R as SeedableRng>::Seed>,
174+
rand::distr::StandardUniform: Distribution<<R as SeedableRng>::Seed>,
175175
{
176176
g.bench_function(name, |b| {
177177
let mut rng = Pcg32::from_os_rng();

benches/benches/standard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use core::time::Duration;
1010
use criterion::measurement::WallTime;
1111
use criterion::{criterion_group, criterion_main, BenchmarkGroup, Criterion};
12-
use rand::distr::{Alphanumeric, Standard};
12+
use rand::distr::{Alphanumeric, StandardUniform};
1313
use rand::prelude::*;
1414
use rand_distr::{Open01, OpenClosed01};
1515
use rand_pcg::Pcg64Mcg;
@@ -34,14 +34,14 @@ where
3434
}
3535

3636
pub fn bench(c: &mut Criterion) {
37-
let mut g = c.benchmark_group("Standard");
37+
let mut g = c.benchmark_group("StandardUniform");
3838
g.sample_size(1000);
3939
g.warm_up_time(Duration::from_millis(500));
4040
g.measurement_time(Duration::from_millis(1000));
4141

4242
macro_rules! do_ty {
4343
($t:ty) => {
44-
bench_ty::<$t, Standard>(&mut g, stringify!($t));
44+
bench_ty::<$t, StandardUniform>(&mut g, stringify!($t));
4545
};
4646
($t:ty, $($tt:ty),*) => {
4747
do_ty!($t);

rand_distr/src/cauchy.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
//! The Cauchy distribution `Cauchy(x₀, γ)`.
1111
12-
use crate::{Distribution, Standard};
12+
use crate::{Distribution, StandardUniform};
1313
use core::fmt;
1414
use num_traits::{Float, FloatConst};
1515
use rand::Rng;
@@ -58,7 +58,7 @@ use rand::Rng;
5858
pub struct Cauchy<F>
5959
where
6060
F: Float + FloatConst,
61-
Standard: Distribution<F>,
61+
StandardUniform: Distribution<F>,
6262
{
6363
median: F,
6464
scale: F,
@@ -85,7 +85,7 @@ impl std::error::Error for Error {}
8585
impl<F> Cauchy<F>
8686
where
8787
F: Float + FloatConst,
88-
Standard: Distribution<F>,
88+
StandardUniform: Distribution<F>,
8989
{
9090
/// Construct a new `Cauchy` with the given shape parameters
9191
/// `median` the peak location and `scale` the scale factor.
@@ -100,11 +100,11 @@ where
100100
impl<F> Distribution<F> for Cauchy<F>
101101
where
102102
F: Float + FloatConst,
103-
Standard: Distribution<F>,
103+
StandardUniform: Distribution<F>,
104104
{
105105
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> F {
106106
// sample from [0, 1)
107-
let x = Standard.sample(rng);
107+
let x = StandardUniform.sample(rng);
108108
// get standard cauchy random number
109109
// note that π/2 is not exactly representable, even if x=0.5 the result is finite
110110
let comp_dev = (F::PI() * x).tan();
@@ -166,7 +166,7 @@ mod test {
166166
fn value_stability() {
167167
fn gen_samples<F: Float + FloatConst + fmt::Debug>(m: F, s: F, buf: &mut [F])
168168
where
169-
Standard: Distribution<F>,
169+
StandardUniform: Distribution<F>,
170170
{
171171
let distr = Cauchy::new(m, s).unwrap();
172172
let mut rng = crate::test::rng(353);

rand_distr/src/inverse_gaussian.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The inverse Gaussian distribution `IG(μ, λ)`.
22
3-
use crate::{Distribution, Standard, StandardNormal};
3+
use crate::{Distribution, StandardNormal, StandardUniform};
44
use core::fmt;
55
use num_traits::Float;
66
use rand::Rng;
@@ -53,7 +53,7 @@ pub struct InverseGaussian<F>
5353
where
5454
F: Float,
5555
StandardNormal: Distribution<F>,
56-
Standard: Distribution<F>,
56+
StandardUniform: Distribution<F>,
5757
{
5858
mean: F,
5959
shape: F,
@@ -63,7 +63,7 @@ impl<F> InverseGaussian<F>
6363
where
6464
F: Float,
6565
StandardNormal: Distribution<F>,
66-
Standard: Distribution<F>,
66+
StandardUniform: Distribution<F>,
6767
{
6868
/// Construct a new `InverseGaussian` distribution with the given mean and
6969
/// shape.
@@ -85,7 +85,7 @@ impl<F> Distribution<F> for InverseGaussian<F>
8585
where
8686
F: Float,
8787
StandardNormal: Distribution<F>,
88-
Standard: Distribution<F>,
88+
StandardUniform: Distribution<F>,
8989
{
9090
#[allow(clippy::many_single_char_names)]
9191
fn sample<R>(&self, rng: &mut R) -> F

rand_distr/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//! The following are re-exported:
3535
//!
3636
//! - The [`Distribution`] trait and [`DistIter`] helper type
37-
//! - The [`Standard`], [`Alphanumeric`], [`Uniform`], [`OpenClosed01`],
37+
//! - The [`StandardUniform`], [`Alphanumeric`], [`Uniform`], [`OpenClosed01`],
3838
//! [`Open01`], [`Bernoulli`], and [`WeightedIndex`] distributions
3939
//!
4040
//! ## Distributions
@@ -95,7 +95,7 @@ use rand::Rng;
9595

9696
pub use rand::distr::{
9797
uniform, Alphanumeric, Bernoulli, BernoulliError, DistIter, Distribution, Open01, OpenClosed01,
98-
Standard, Uniform,
98+
StandardUniform, Uniform,
9999
};
100100

101101
pub use self::beta::{Beta, Error as BetaError};

rand_distr/src/normal_inverse_gaussian.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Distribution, InverseGaussian, Standard, StandardNormal};
1+
use crate::{Distribution, InverseGaussian, StandardNormal, StandardUniform};
22
use core::fmt;
33
use num_traits::Float;
44
use rand::Rng;
@@ -54,7 +54,7 @@ pub struct NormalInverseGaussian<F>
5454
where
5555
F: Float,
5656
StandardNormal: Distribution<F>,
57-
Standard: Distribution<F>,
57+
StandardUniform: Distribution<F>,
5858
{
5959
beta: F,
6060
inverse_gaussian: InverseGaussian<F>,
@@ -64,7 +64,7 @@ impl<F> NormalInverseGaussian<F>
6464
where
6565
F: Float,
6666
StandardNormal: Distribution<F>,
67-
Standard: Distribution<F>,
67+
StandardUniform: Distribution<F>,
6868
{
6969
/// Construct a new `NormalInverseGaussian` distribution with the given alpha (tail heaviness) and
7070
/// beta (asymmetry) parameters.
@@ -94,7 +94,7 @@ impl<F> Distribution<F> for NormalInverseGaussian<F>
9494
where
9595
F: Float,
9696
StandardNormal: Distribution<F>,
97-
Standard: Distribution<F>,
97+
StandardUniform: Distribution<F>,
9898
{
9999
fn sample<R>(&self, rng: &mut R) -> F
100100
where

0 commit comments

Comments
 (0)