From 8c571e030bec9a2223c48f7a5938050b476fb8a7 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 28 Nov 2024 08:39:50 +0000 Subject: [PATCH 1/8] CHANGELOG: restore mention of removing isize/usize sampling --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 974ff20551..533e472af5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ This is a pre-release. To depend on this version, use `rand = "=0.9.0-beta.0"` t - Distribution `Uniform` implements `TryFrom` instead of `From` for ranges (#1229) - Optimize distribution `Uniform`: use Canon's method (single sampling) / Lemire's method (distribution sampling) for faster sampling (breaks value stability; #1287) - Add `UniformUsize` and use to make `Uniform` for `usize` portable (#1487) +- Remove support for generating `isize` and `usize` values with `Standard`, `Uniform` (except via `UniformUsize`) and `Fill` and usage as a `WeightedAliasIndex` weight (#1487) - Optimize fn `sample_single_inclusive` for floats (+~20% perf) (#1289) - Allow `UniformFloat::new` samples and `UniformFloat::sample_single` to yield `high` (#1462) - Add impl `DistString` for distributions `Slice` and `Uniform` (#1315) From 3acac52ed9a08a2a9ab790b9a9ce0e87757f178c Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 15:07:26 +0000 Subject: [PATCH 2/8] Remove fn OsError::code This is not supported in getrandom v0.3 --- rand_core/src/os.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/rand_core/src/os.rs b/rand_core/src/os.rs index 44efe700c1..73c9681094 100644 --- a/rand_core/src/os.rs +++ b/rand_core/src/os.rs @@ -79,15 +79,6 @@ impl OsError { pub fn raw_os_error(self) -> Option { self.0.raw_os_error() } - - /// Extract the bare error code. - /// - /// This code can either come from the underlying OS, or be a custom error. - /// Use [`OsError::raw_os_error()`] to disambiguate. - #[inline] - pub const fn code(self) -> core::num::NonZeroU32 { - self.0.code() - } } impl TryRngCore for OsRng { From 2a7f32671eb7d5f793ccb650c1f804aaf83db028 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 15:08:35 +0000 Subject: [PATCH 3/8] Update to getrandom v0.3.0-rc.0 --- rand_core/Cargo.toml | 2 +- rand_core/src/lib.rs | 2 +- rand_core/src/os.rs | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 40fa31be02..134212d2f2 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -32,5 +32,5 @@ serde = ["dep:serde"] # enables serde for BlockRng wrapper [dependencies] serde = { version = "1", features = ["derive"], optional = true } -getrandom = { version = "0.2", optional = true } +getrandom = { version = "0.3.0-rc.0", optional = true } zerocopy = { version = "0.8.0", default-features = false } diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index adc7177081..fafa4e40bd 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -512,7 +512,7 @@ pub trait SeedableRng: Sized { #[cfg(feature = "os_rng")] fn try_from_os_rng() -> Result { let mut seed = Self::Seed::default(); - getrandom::getrandom(seed.as_mut())?; + getrandom::fill(seed.as_mut())?; let res = Self::from_seed(seed); Ok(res) } diff --git a/rand_core/src/os.rs b/rand_core/src/os.rs index 73c9681094..06e724554d 100644 --- a/rand_core/src/os.rs +++ b/rand_core/src/os.rs @@ -9,7 +9,6 @@ //! Interface to the random number generator of the operating system. use crate::{TryCryptoRng, TryRngCore}; -use getrandom::getrandom; /// An interface over the operating-system's random data source /// @@ -87,20 +86,20 @@ impl TryRngCore for OsRng { #[inline] fn try_next_u32(&mut self) -> Result { let mut buf = [0u8; 4]; - getrandom(&mut buf).map_err(OsError)?; + getrandom::fill(&mut buf).map_err(OsError)?; Ok(u32::from_ne_bytes(buf)) } #[inline] fn try_next_u64(&mut self) -> Result { let mut buf = [0u8; 8]; - getrandom(&mut buf).map_err(OsError)?; + getrandom::fill(&mut buf).map_err(OsError)?; Ok(u64::from_ne_bytes(buf)) } #[inline] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> { - getrandom(dest).map_err(OsError)?; + getrandom::fill(dest).map_err(OsError)?; Ok(()) } } From 5f2e19676f7f803a81911b0f434ccf043b87330d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 15:08:53 +0000 Subject: [PATCH 4/8] Bump versions, CHANGELOG notes --- CHANGELOG.md | 3 +++ Cargo.toml | 8 ++++---- README.md | 2 +- distr_test/Cargo.toml | 2 +- rand_chacha/CHANGELOG.md | 3 +++ rand_chacha/Cargo.toml | 6 +++--- rand_core/CHANGELOG.md | 3 +++ rand_core/Cargo.toml | 2 +- rand_distr/CHANGELOG.md | 3 +++ rand_distr/Cargo.toml | 8 ++++---- rand_pcg/CHANGELOG.md | 3 +++ rand_pcg/Cargo.toml | 6 +++--- 12 files changed, 32 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 533e472af5..42e5eb5a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md). You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful. +## [0.9.0-beta.1] - 2024-11-30 +- Bump `rand_core` version + ## [0.9.0-beta.0] - 2024-11-25 This is a pre-release. To depend on this version, use `rand = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes). diff --git a/Cargo.toml b/Cargo.toml index bd6c2d2c4d..6741753bf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand" -version = "0.9.0-beta.0" +version = "0.9.0-beta.1" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -69,14 +69,14 @@ members = [ exclude = ["benches", "distr_test"] [dependencies] -rand_core = { path = "rand_core", version = "=0.9.0-beta.0", default-features = false } +rand_core = { path = "rand_core", version = "=0.9.0-beta.1", default-features = false } log = { version = "0.4.4", optional = true } serde = { version = "1.0.103", features = ["derive"], optional = true } -rand_chacha = { path = "rand_chacha", version = "=0.9.0-beta.0", default-features = false, optional = true } +rand_chacha = { path = "rand_chacha", version = "=0.9.0-beta.1", default-features = false, optional = true } zerocopy = { version = "0.8.0", default-features = false, features = ["simd"] } [dev-dependencies] -rand_pcg = { path = "rand_pcg", version = "=0.9.0-beta.0" } +rand_pcg = { path = "rand_pcg", version = "=0.9.0-beta.1" } # Only to test serde bincode = "1.2.1" rayon = "1.7" diff --git a/README.md b/README.md index dc8fc78016..e633ef3383 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ rand = "0.8.5" Or, to try the 0.9.0 beta release: ```toml [dependencies] -rand = "=0.9.0-beta.0" +rand = "=0.9.0-beta.1" ``` To get started using Rand, see [The Book](https://rust-random.github.io/book). diff --git a/distr_test/Cargo.toml b/distr_test/Cargo.toml index 801b0c2e81..ecee771f54 100644 --- a/distr_test/Cargo.toml +++ b/distr_test/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dev-dependencies] rand_distr = { path = "../rand_distr", version = "=0.5.0-beta.1", default-features = false, features = ["alloc"] } -rand = { path = "..", version = "=0.9.0-beta.0", features = ["small_rng"] } +rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] } num-traits = "0.2.19" # Special functions for testing distributions special = "0.11.0" diff --git a/rand_chacha/CHANGELOG.md b/rand_chacha/CHANGELOG.md index af8aa1f9ec..4f33c2cde7 100644 --- a/rand_chacha/CHANGELOG.md +++ b/rand_chacha/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.0-beta.1] - 2024-11-30 +- Bump `rand_core` version + ## [0.9.0-beta.0] - 2024-11-25 This is a pre-release. To depend on this version, use `rand_chacha = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes). diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index 096d77c9b7..6438e833c5 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_chacha" -version = "0.9.0-beta.0" +version = "0.9.0-beta.1" authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -20,14 +20,14 @@ all-features = true rustdoc-args = ["--generate-link-to-definition"] [dependencies] -rand_core = { path = "../rand_core", version = "=0.9.0-beta.0" } +rand_core = { path = "../rand_core", version = "=0.9.0-beta.1" } ppv-lite86 = { version = "0.2.14", default-features = false, features = ["simd"] } serde = { version = "1.0", features = ["derive"], optional = true } [dev-dependencies] # Only to test serde serde_json = "1.0" -rand_core = { path = "../rand_core", version = "=0.9.0-beta.0", features = ["os_rng"] } +rand_core = { path = "../rand_core", version = "=0.9.0-beta.1", features = ["os_rng"] } [features] default = ["std"] diff --git a/rand_core/CHANGELOG.md b/rand_core/CHANGELOG.md index b22a6ea34c..327a98c095 100644 --- a/rand_core/CHANGELOG.md +++ b/rand_core/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.0-beta.1] - 2024-11-30 +- Update to `getrandom` v0.3.0-rc.0 + ## [0.9.0-beta.0] - 2024-11-25 This is a pre-release. To depend on this version, use `rand_core = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes). diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 134212d2f2..d3f6caee62 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_core" -version = "0.9.0-beta.0" +version = "0.9.0-beta.1" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/rand_distr/CHANGELOG.md b/rand_distr/CHANGELOG.md index 6748234a58..a4ee5fb022 100644 --- a/rand_distr/CHANGELOG.md +++ b/rand_distr/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.0-beta.2] - 2024-11-30 +- Bump `rand` version + ## [0.5.0-beta.1] - 2024-11-27 - Fix docs.rs build (#1539) diff --git a/rand_distr/Cargo.toml b/rand_distr/Cargo.toml index f3433e3659..3d7477518a 100644 --- a/rand_distr/Cargo.toml +++ b/rand_distr/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_distr" -version = "0.5.0-beta.1" +version = "0.5.0-beta.2" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -33,15 +33,15 @@ std_math = ["num-traits/std"] serde = ["dep:serde", "dep:serde_with", "rand/serde"] [dependencies] -rand = { path = "..", version = "=0.9.0-beta.0", default-features = false } +rand = { path = "..", version = "=0.9.0-beta.1", default-features = false } num-traits = { version = "0.2", default-features = false, features = ["libm"] } serde = { version = "1.0.103", features = ["derive"], optional = true } serde_with = { version = ">= 3.0, <= 3.11", optional = true } [dev-dependencies] -rand_pcg = { version = "=0.9.0-beta.0", path = "../rand_pcg" } +rand_pcg = { version = "=0.9.0-beta.1", path = "../rand_pcg" } # For inline examples -rand = { path = "..", version = "=0.9.0-beta.0", features = ["small_rng"] } +rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] } # Histogram implementation for testing uniformity average = { version = "0.15", features = [ "std" ] } # Special functions for testing distributions diff --git a/rand_pcg/CHANGELOG.md b/rand_pcg/CHANGELOG.md index 5b9cd14005..f3e50819c2 100644 --- a/rand_pcg/CHANGELOG.md +++ b/rand_pcg/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.0-beta.1] - 2024-11-30 +- Bump `rand_core` version + ## [0.9.0-beta.0] - 2024-11-25 This is a pre-release. To depend on this version, use `rand_chacha = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes). diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index e490c1bc1a..3ba620a7a6 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_pcg" -version = "0.9.0-beta.0" +version = "0.9.0-beta.1" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -24,7 +24,7 @@ serde = ["dep:serde"] os_rng = ["rand_core/os_rng"] [dependencies] -rand_core = { path = "../rand_core", version = "=0.9.0-beta.0" } +rand_core = { path = "../rand_core", version = "=0.9.0-beta.1" } serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] @@ -32,4 +32,4 @@ serde = { version = "1", features = ["derive"], optional = true } # deps yet, see: https://github.com/rust-lang/cargo/issues/1596 # Versions prior to 1.1.4 had incorrect minimal dependencies. bincode = { version = "1.1.4" } -rand_core = { path = "../rand_core", version = "=0.9.0-beta.0", features = ["os_rng"] } +rand_core = { path = "../rand_core", version = "=0.9.0-beta.1", features = ["os_rng"] } From 14d5f143083ab4fae8ccac2be84f0c70ae010f33 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 15:42:44 +0000 Subject: [PATCH 5/8] Remove rand_core feature alloc This is unused --- Cargo.toml | 2 +- rand_core/Cargo.toml | 3 +-- rand_core/src/lib.rs | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6741753bf1..ac47d4a125 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ serde = ["dep:serde", "rand_core/serde"] std = ["rand_core/std", "rand_chacha?/std", "alloc"] # Option: "alloc" enables support for Vec and Box when not using "std" -alloc = ["rand_core/alloc"] +alloc = [] # Option: enable OsRng os_rng = ["rand_core/os_rng"] diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index d3f6caee62..c932b9b88f 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -25,8 +25,7 @@ rustdoc-args = ["--generate-link-to-definition"] all-features = true [features] -std = ["alloc", "getrandom?/std"] -alloc = [] # enables Vec and Box support without std +std = ["getrandom?/std"] os_rng = ["dep:getrandom"] serde = ["dep:serde"] # enables serde for BlockRng wrapper diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index fafa4e40bd..babc0e349a 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -35,8 +35,6 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![no_std] -#[cfg(feature = "alloc")] -extern crate alloc; #[cfg(feature = "std")] extern crate std; From 60ede7d3054020dff9d1fdf0d18b4e7e3d319eba Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 15:45:54 +0000 Subject: [PATCH 6/8] Update README Much of this information is outdated and/or irrelevant --- rand_core/README.md | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/rand_core/README.md b/rand_core/README.md index 98fb7c9a79..3a3584255a 100644 --- a/rand_core/README.md +++ b/rand_core/README.md @@ -42,34 +42,9 @@ The traits and error types are also available via `rand`. The current version is: ``` -rand_core = "0.6.4" +rand_core = "=0.9.0-beta.1" ``` -Rand libs have inter-dependencies and make use of the -[semver trick](https://github.com/dtolnay/semver-trick/) in order to make traits -compatible across crate versions. (This is especially important for `RngCore` -and `SeedableRng`.) A few crate releases are thus compatibility shims, -depending on the *next* lib version (e.g. `rand_core` versions `0.2.2` and -`0.3.1`). This means, for example, that `rand_core_0_4_0::SeedableRng` and -`rand_core_0_3_0::SeedableRng` are distinct, incompatible traits, which can -cause build errors. Usually, running `cargo update` is enough to fix any issues. - -## Crate Features - -`rand_core` supports `no_std` and `alloc`-only configurations, as well as full -`std` functionality. The differences between `no_std` and full `std` are small, -comprising `RngCore` support for `Box` types where `R: RngCore`, -`std::io::Read` support for types supporting `RngCore`, and -extensions to the `Error` type's functionality. - -The `std` feature is *not enabled by default*. This is primarily to avoid build -problems where one crate implicitly requires `rand_core` with `std` support and -another crate requires `rand` *without* `std` support. However, the `rand` crate -continues to enable `std` support by default, both for itself and `rand_core`. - -The `serde` feature can be used to derive `Serialize` and `Deserialize` for RNG -implementations that use the `BlockRng` or `BlockRng64` wrappers. - # License From 160c8917495d686a15ab61f82915f67390e28a49 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 16:41:59 +0000 Subject: [PATCH 7/8] Use getrandom::u32 / u64 --- rand_core/src/os.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/rand_core/src/os.rs b/rand_core/src/os.rs index 06e724554d..49111632d9 100644 --- a/rand_core/src/os.rs +++ b/rand_core/src/os.rs @@ -85,22 +85,17 @@ impl TryRngCore for OsRng { #[inline] fn try_next_u32(&mut self) -> Result { - let mut buf = [0u8; 4]; - getrandom::fill(&mut buf).map_err(OsError)?; - Ok(u32::from_ne_bytes(buf)) + getrandom::u32().map_err(OsError) } #[inline] fn try_next_u64(&mut self) -> Result { - let mut buf = [0u8; 8]; - getrandom::fill(&mut buf).map_err(OsError)?; - Ok(u64::from_ne_bytes(buf)) + getrandom::u64().map_err(OsError) } #[inline] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> { - getrandom::fill(dest).map_err(OsError)?; - Ok(()) + getrandom::fill(dest).map_err(OsError) } } From a2988d62e0404a490a7eb1ee9fcd656b7a579b3f Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 29 Nov 2024 16:51:14 +0000 Subject: [PATCH 8/8] Fixes --- .github/workflows/test.yml | 2 +- distr_test/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5088ddcf2..9858b0f41a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -121,7 +121,7 @@ jobs: run: | cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features - cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc,os_rng + cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=os_rng - name: Test rand_distr run: | cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde diff --git a/distr_test/Cargo.toml b/distr_test/Cargo.toml index ecee771f54..2092595998 100644 --- a/distr_test/Cargo.toml +++ b/distr_test/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dev-dependencies] -rand_distr = { path = "../rand_distr", version = "=0.5.0-beta.1", default-features = false, features = ["alloc"] } +rand_distr = { path = "../rand_distr", version = "=0.5.0-beta.2", default-features = false, features = ["alloc"] } rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] } num-traits = "0.2.19" # Special functions for testing distributions