Skip to content

Commit 16eb7de

Browse files
authored
Add the thread_rng feature flag (#1547)
1 parent afa24e4 commit 16eb7de

File tree

9 files changed

+31
-22
lines changed

9 files changed

+31
-22
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ 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+
## [0.9.0-beta.3] - 2025-01-03
12+
- Add feature `thread_rng` (#1547)
13+
1114
## [0.9.0-beta.1] - 2024-11-30
1215
- Bump `rand_core` version
1316

Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand"
3-
version = "0.9.0-beta.1"
3+
version = "0.9.0-beta.3"
44
authors = ["The Rand Project Developers", "The Rust Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"
@@ -28,7 +28,7 @@ features = ["small_rng", "serde"]
2828

2929
[features]
3030
# Meta-features:
31-
default = ["std", "std_rng", "os_rng", "small_rng"]
31+
default = ["std", "std_rng", "os_rng", "small_rng", "thread_rng"]
3232
nightly = [] # some additions requiring nightly Rust
3333
serde = ["dep:serde", "rand_core/serde"]
3434

@@ -51,6 +51,9 @@ std_rng = ["dep:rand_chacha"]
5151
# Option: enable SmallRng
5252
small_rng = []
5353

54+
# Option: enable ThreadRng and rng()
55+
thread_rng = ["std", "std_rng", "os_rng"]
56+
5457
# Option: use unbiased sampling for algorithms supporting this option: Uniform distribution.
5558
# By default, bias affecting no more than one in 2^48 samples is accepted.
5659
# Note: enabling this option is expected to affect reproducibility of results.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ rand = "0.8.5"
6464
Or, to try the 0.9.0 beta release:
6565
```toml
6666
[dependencies]
67-
rand = "=0.9.0-beta.1"
67+
rand = "=0.9.0-beta.3"
6868
```
6969

7070
To get started using Rand, see [The Book](https://rust-random.github.io/book).

distr_test/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ edition = "2021"
55
publish = false
66

77
[dev-dependencies]
8-
rand_distr = { path = "../rand_distr", version = "=0.5.0-beta.2", default-features = false, features = ["alloc"] }
9-
rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] }
8+
rand_distr = { path = "../rand_distr", version = "=0.5.0-beta.3", default-features = false, features = ["alloc"] }
9+
rand = { path = "..", version = "=0.9.0-beta.3", features = ["small_rng"] }
1010
num-traits = "0.2.19"
1111
# Special functions for testing distributions
1212
special = "0.11.0"

rand_distr/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.0-beta.3] - 2025-01-03
8+
- Bump `rand` version (#1547)
9+
710
## [0.5.0-beta.2] - 2024-11-30
811
- Bump `rand` version
912

rand_distr/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_distr"
3-
version = "0.5.0-beta.2"
3+
version = "0.5.0-beta.3"
44
authors = ["The Rand Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"
@@ -33,15 +33,15 @@ std_math = ["num-traits/std"]
3333
serde = ["dep:serde", "dep:serde_with", "rand/serde"]
3434

3535
[dependencies]
36-
rand = { path = "..", version = "=0.9.0-beta.1", default-features = false }
36+
rand = { path = "..", version = "=0.9.0-beta.3", default-features = false }
3737
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
3838
serde = { version = "1.0.103", features = ["derive"], optional = true }
3939
serde_with = { version = ">= 3.0, <= 3.11", optional = true }
4040

4141
[dev-dependencies]
4242
rand_pcg = { version = "=0.9.0-beta.1", path = "../rand_pcg" }
4343
# For inline examples
44-
rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] }
44+
rand = { path = "..", version = "=0.9.0-beta.3", features = ["small_rng"] }
4545
# Histogram implementation for testing uniformity
4646
average = { version = "0.15", features = [ "std" ] }
4747
# Special functions for testing distributions

src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ pub mod rngs;
103103
pub mod seq;
104104

105105
// Public exports
106-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
106+
#[cfg(feature = "thread_rng")]
107107
pub use crate::rngs::thread::rng;
108108

109109
/// Access the thread-local generator
110110
///
111111
/// Use [`rand::rng()`](rng()) instead.
112-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
112+
#[cfg(feature = "thread_rng")]
113113
#[deprecated(since = "0.9.0", note = "renamed to `rng`")]
114114
#[inline]
115115
pub fn thread_rng() -> crate::rngs::ThreadRng {
@@ -118,7 +118,7 @@ pub fn thread_rng() -> crate::rngs::ThreadRng {
118118

119119
pub use rng::{Fill, Rng};
120120

121-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
121+
#[cfg(feature = "thread_rng")]
122122
use crate::distr::{Distribution, StandardUniform};
123123

124124
/// Generate a random value using the thread-local random number generator.
@@ -159,7 +159,7 @@ use crate::distr::{Distribution, StandardUniform};
159159
///
160160
/// [`StandardUniform`]: distr::StandardUniform
161161
/// [`ThreadRng`]: rngs::ThreadRng
162-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
162+
#[cfg(feature = "thread_rng")]
163163
#[inline]
164164
pub fn random<T>() -> T
165165
where
@@ -179,7 +179,7 @@ where
179179
/// let v: Vec<i32> = rand::random_iter().take(5).collect();
180180
/// println!("{v:?}");
181181
/// ```
182-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
182+
#[cfg(feature = "thread_rng")]
183183
#[inline]
184184
pub fn random_iter<T>() -> distr::DistIter<StandardUniform, rngs::ThreadRng, T>
185185
where
@@ -204,7 +204,7 @@ where
204204
/// ```
205205
/// Note that the first example can also be achieved (without `collect`'ing
206206
/// to a `Vec`) using [`seq::IteratorRandom::choose`].
207-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
207+
#[cfg(feature = "thread_rng")]
208208
#[inline]
209209
pub fn random_range<T, R>(range: R) -> T
210210
where
@@ -228,7 +228,7 @@ where
228228
/// # Panics
229229
///
230230
/// If `p < 0` or `p > 1`.
231-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
231+
#[cfg(feature = "thread_rng")]
232232
#[inline]
233233
#[track_caller]
234234
pub fn random_bool(p: f64) -> bool {
@@ -260,7 +260,7 @@ pub fn random_bool(p: f64) -> bool {
260260
/// ```
261261
///
262262
/// [`Bernoulli`]: distr::Bernoulli
263-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
263+
#[cfg(feature = "thread_rng")]
264264
#[inline]
265265
#[track_caller]
266266
pub fn random_ratio(numerator: u32, denominator: u32) -> bool {
@@ -282,7 +282,7 @@ pub fn random_ratio(numerator: u32, denominator: u32) -> bool {
282282
/// Note that you can instead use [`random()`] to generate an array of random
283283
/// data, though this is slower for small elements (smaller than the RNG word
284284
/// size).
285-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
285+
#[cfg(feature = "thread_rng")]
286286
#[inline]
287287
#[track_caller]
288288
pub fn fill<T: Fill + ?Sized>(dest: &mut T) {
@@ -302,7 +302,7 @@ mod test {
302302
}
303303

304304
#[test]
305-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
305+
#[cfg(feature = "thread_rng")]
306306
fn test_random() {
307307
let _n: u64 = random();
308308
let _f: f32 = random();
@@ -316,7 +316,7 @@ mod test {
316316
}
317317

318318
#[test]
319-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
319+
#[cfg(feature = "thread_rng")]
320320
fn test_range() {
321321
let _n: usize = random_range(42..=43);
322322
let _f: f32 = random_range(42.0..43.0);

src/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use crate::rngs::SmallRng;
2727
#[doc(no_inline)]
2828
pub use crate::rngs::StdRng;
2929
#[doc(no_inline)]
30-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
30+
#[cfg(feature = "thread_rng")]
3131
pub use crate::rngs::ThreadRng;
3232
#[doc(no_inline)]
3333
pub use crate::seq::{IndexedMutRandom, IndexedRandom, IteratorRandom, SliceRandom};

src/rngs/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ mod xoshiro256plusplus;
9595

9696
#[cfg(feature = "std_rng")]
9797
mod std;
98-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
98+
#[cfg(feature = "thread_rng")]
9999
pub(crate) mod thread;
100100

101101
#[cfg(feature = "small_rng")]
102102
pub use self::small::SmallRng;
103103
#[cfg(feature = "std_rng")]
104104
pub use self::std::StdRng;
105-
#[cfg(all(feature = "std", feature = "std_rng", feature = "os_rng"))]
105+
#[cfg(feature = "thread_rng")]
106106
pub use self::thread::ThreadRng;
107107

108108
#[cfg(feature = "os_rng")]

0 commit comments

Comments
 (0)