Skip to content

Commit fdaf424

Browse files
committed
Deprecate rand::rngs::mock module and StepRng
1 parent db993ec commit fdaf424

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md).
88

99
You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful.
1010

11+
## [Unreleased]
12+
### Deprecated
13+
- Deprecate `rand::rngs::mock` module and `StepRng` generator (#1634)
14+
1115
## [0.9.1] - 2025-04-17
1216
### Security and unsafe
1317
- Revise "not a crypto library" policy again (#1565)

src/rng.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ pub trait Rng: RngCore {
110110
/// # Example
111111
///
112112
/// ```
113-
/// use rand::{rngs::mock::StepRng, Rng};
113+
/// use rand::{rngs::SmallRng, Rng, SeedableRng};
114114
///
115-
/// let rng = StepRng::new(1, 1);
115+
/// let rng = SmallRng::seed_from_u64(0);
116116
/// let v: Vec<i32> = rng.random_iter().take(5).collect();
117-
/// assert_eq!(&v, &[1, 2, 3, 4, 5]);
117+
/// assert_eq!(v.len(), 5);
118118
/// ```
119119
#[inline]
120120
fn random_iter<T>(self) -> distr::Iter<StandardUniform, Self, T>

src/rngs/mock.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
//! Mock random number generator
1010
11+
#![allow(deprecated)]
12+
1113
use rand_core::{impls, RngCore};
1214

1315
#[cfg(feature = "serde")]
@@ -31,6 +33,7 @@ use serde::{Deserialize, Serialize};
3133
/// # Example
3234
///
3335
/// ```
36+
/// # #![allow(deprecated)]
3437
/// use rand::Rng;
3538
/// use rand::rngs::mock::StepRng;
3639
///
@@ -40,6 +43,7 @@ use serde::{Deserialize, Serialize};
4043
/// ```
4144
#[derive(Debug, Clone, PartialEq, Eq)]
4245
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
46+
#[deprecated(since = "0.9.2", note = "Deprecated without replacement")]
4347
pub struct StepRng {
4448
v: u64,
4549
a: u64,

src/rngs/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
mod reseeding;
8181
pub use reseeding::ReseedingRng;
8282

83+
#[deprecated(since = "0.9.2")]
8384
pub mod mock; // Public so we don't export `StepRng` directly, making it a bit
8485
// more clear it is intended for testing.
8586

0 commit comments

Comments
 (0)