diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d356251cc9..668c0f08b52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ 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. -## Unreleased +## [0.7.0 Pre-release] - 2019-06-06 +Many changes (TODO) - Enable fork protection of ReseedingRng without `std` - Remove dependency on `winapi` diff --git a/Cargo.toml b/Cargo.toml index aeba2397d5e..8ce6f3cdbb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand" -version = "0.6.5" +version = "0.7.0-pre.0" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" @@ -54,7 +54,7 @@ members = [ ] [dependencies] -rand_core = { path = "rand_core", version = "0.4" } +rand_core = { path = "rand_core", version = "0.5" } rand_pcg = { path = "rand_pcg", version = "0.1", optional = true } # Do not depend on 'getrandom_package' directly; use the 'getrandom' feature! getrandom_package = { version = "0.1.1", package = "getrandom", optional = true } @@ -114,4 +114,4 @@ required-features = ["small_rng"] all-features = true [patch.crates-io] -rand_core = { path = "rand_core", version = "0.4" } +rand_core = { path = "rand_core", version = "0.5" } diff --git a/rand_chacha/CHANGELOG.md b/rand_chacha/CHANGELOG.md index a1979f601cb..dbf91f9df0d 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.2.0] - 2019-06-06 +- Rewrite based on the much faster `c2-chacha` crate (#789) + ## [0.1.1] - 2019-01-04 - Disable `i128` and `u128` if the `target_os` is `emscripten` (#671: work-around Emscripten limitation) - Update readme and doc links diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index 43759ec4ab1..84acf5a580c 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_chacha" -version = "0.2.1" +version = "0.2.0" authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" readme = "README.md" @@ -19,7 +19,7 @@ travis-ci = { repository = "rust-random/rand" } appveyor = { repository = "rust-random/rand" } [dependencies] -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } c2-chacha = { version = "0.2.2", default-features = false } [build-dependencies] diff --git a/rand_chacha/README.md b/rand_chacha/README.md index b653567e8e0..c15611ee4c3 100644 --- a/rand_chacha/README.md +++ b/rand_chacha/README.md @@ -16,11 +16,14 @@ as an RNG. It is an improved variant of the Salsa20 cipher family, which was selected as one of the "stream ciphers suitable for widespread adoption" by eSTREAM[^2]. +The RNGs provided by this crate are implemented via the fast stream ciphers of +the [`c2-chacha`](https://crates.io/crates/c2-chacha) crate. + Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_chacha) - [API documentation (docs.rs)](https://docs.rs/rand_chacha) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_chacha/CHANGELOG.md) [rand]: https://crates.io/crates/rand [^1]: D. J. Bernstein, [*ChaCha, a variant of Salsa20*]( diff --git a/rand_core/CHANGELOG.md b/rand_core/CHANGELOG.md index 7f2d7978fdc..4542a3b6f9d 100644 --- a/rand_core/CHANGELOG.md +++ b/rand_core/CHANGELOG.md @@ -4,6 +4,11 @@ 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] - 2019-06-06 +- Enable testing with Miri and fix incorrect pointer usages (#779, #780, #781, #783, #784) +- Rewrite `Error` type and adjust API (#800) +- Adjust usage of `#[inline]` for `BlockRng` and `BlockRng64` + ## [0.4.0] - 2019-01-24 - Disable the `std` feature by default (#702) diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 8c39865486a..dbbc5c5be6c 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_core" -version = "0.4.0" +version = "0.5.0" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" diff --git a/rand_core/README.md b/rand_core/README.md index 1066456105f..467e66f98b6 100644 --- a/rand_core/README.md +++ b/rand_core/README.md @@ -25,7 +25,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_core) - [API documentation (docs.rs)](https://docs.rs/rand_core) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_core/CHANGELOG.md) [rand]: https://crates.io/crates/rand @@ -42,6 +42,11 @@ The traits and error types are also available via `rand`. ## Versions +The current version is: +``` +rand_core = "0.5.0" +``` + 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` diff --git a/rand_core/src/block.rs b/rand_core/src/block.rs index 6c5beca271a..e4f07e74bc7 100644 --- a/rand_core/src/block.rs +++ b/rand_core/src/block.rs @@ -131,6 +131,7 @@ impl fmt::Debug for BlockRng { impl BlockRng { /// Create a new `BlockRng` from an existing RNG implementing /// `BlockRngCore`. Results will be generated on first use. + #[inline] pub fn new(core: R) -> BlockRng{ let results_empty = R::Results::default(); BlockRng { @@ -145,18 +146,21 @@ impl BlockRng { /// If this is equal to or larger than the size of the result buffer then /// the buffer is "empty" and `generate()` must be called to produce new /// results. + #[inline(always)] pub fn index(&self) -> usize { self.index } /// Reset the number of available results. /// This will force a new set of results to be generated on next use. + #[inline] pub fn reset(&mut self) { self.index = self.results.as_ref().len(); } /// Generate a new set of results immediately, setting the index to the /// given value. + #[inline] pub fn generate_and_set(&mut self, index: usize) { assert!(index < self.results.as_ref().len()); self.core.generate(&mut self.results); @@ -167,7 +171,7 @@ impl BlockRng { impl> RngCore for BlockRng where ::Results: AsRef<[u32]> + AsMut<[u32]> { - #[inline(always)] + #[inline] fn next_u32(&mut self) -> u32 { if self.index >= self.results.as_ref().len() { self.generate_and_set(0); @@ -178,7 +182,7 @@ where ::Results: AsRef<[u32]> + AsMut<[u32]> value } - #[inline(always)] + #[inline] fn next_u64(&mut self) -> u64 { let read_u64 = |results: &[u32], index| { if cfg!(any(target_endian = "little")) { @@ -210,6 +214,7 @@ where ::Results: AsRef<[u32]> + AsMut<[u32]> } } + #[inline] fn fill_bytes(&mut self, dest: &mut [u8]) { let mut read_len = 0; while read_len < dest.len() { @@ -225,23 +230,26 @@ where ::Results: AsRef<[u32]> + AsMut<[u32]> } } + #[inline(always)] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) + Ok(self.fill_bytes(dest)) } } impl SeedableRng for BlockRng { type Seed = R::Seed; + #[inline(always)] fn from_seed(seed: Self::Seed) -> Self { Self::new(R::from_seed(seed)) } + #[inline(always)] fn seed_from_u64(seed: u64) -> Self { Self::new(R::seed_from_u64(seed)) } + #[inline(always)] fn from_rng(rng: S) -> Result { Ok(Self::new(R::from_rng(rng)?)) } @@ -296,6 +304,7 @@ impl fmt::Debug for BlockRng64 { impl BlockRng64 { /// Create a new `BlockRng` from an existing RNG implementing /// `BlockRngCore`. Results will be generated on first use. + #[inline] pub fn new(core: R) -> BlockRng64{ let results_empty = R::Results::default(); BlockRng64 { @@ -311,12 +320,14 @@ impl BlockRng64 { /// If this is equal to or larger than the size of the result buffer then /// the buffer is "empty" and `generate()` must be called to produce new /// results. + #[inline(always)] pub fn index(&self) -> usize { self.index } /// Reset the number of available results. /// This will force a new set of results to be generated on next use. + #[inline] pub fn reset(&mut self) { self.index = self.results.as_ref().len(); self.half_used = false; @@ -324,6 +335,7 @@ impl BlockRng64 { /// Generate a new set of results immediately, setting the index to the /// given value. + #[inline] pub fn generate_and_set(&mut self, index: usize) { assert!(index < self.results.as_ref().len()); self.core.generate(&mut self.results); @@ -335,7 +347,7 @@ impl BlockRng64 { impl> RngCore for BlockRng64 where ::Results: AsRef<[u64]> + AsMut<[u64]> { - #[inline(always)] + #[inline] fn next_u32(&mut self) -> u32 { let mut index = self.index * 2 - self.half_used as usize; if index >= self.results.as_ref().len() * 2 { @@ -361,7 +373,7 @@ where ::Results: AsRef<[u64]> + AsMut<[u64]> } } - #[inline(always)] + #[inline] fn next_u64(&mut self) -> u64 { if self.index >= self.results.as_ref().len() { self.core.generate(&mut self.results); @@ -374,6 +386,7 @@ where ::Results: AsRef<[u64]> + AsMut<[u64]> value } + #[inline] fn fill_bytes(&mut self, dest: &mut [u8]) { let mut read_len = 0; self.half_used = false; @@ -392,6 +405,7 @@ where ::Results: AsRef<[u64]> + AsMut<[u64]> } } + #[inline(always)] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { Ok(self.fill_bytes(dest)) } @@ -400,14 +414,17 @@ where ::Results: AsRef<[u64]> + AsMut<[u64]> impl SeedableRng for BlockRng64 { type Seed = R::Seed; + #[inline(always)] fn from_seed(seed: Self::Seed) -> Self { Self::new(R::from_seed(seed)) } + #[inline(always)] fn seed_from_u64(seed: u64) -> Self { Self::new(R::seed_from_u64(seed)) } + #[inline(always)] fn from_rng(rng: S) -> Result { Ok(Self::new(R::from_rng(rng)?)) } diff --git a/rand_distr/Cargo.toml b/rand_distr/Cargo.toml index 4c387a5b8c5..568854c4385 100644 --- a/rand_distr/Cargo.toml +++ b/rand_distr/Cargo.toml @@ -19,7 +19,7 @@ travis-ci = { repository = "rust-random/rand" } appveyor = { repository = "rust-random/rand" } [dependencies] -rand = { path = "..", version = ">=0.5, <=0.7" } +rand = { path = "..", version = ">=0.5, <=0.7.0-pre.9" } [dev-dependencies] rand_pcg = { version = "0.1", path = "../rand_pcg" } diff --git a/rand_hc/CHANGELOG.md b/rand_hc/CHANGELOG.md index d0c4a2fcbc5..2820275e1c7 100644 --- a/rand_hc/CHANGELOG.md +++ b/rand_hc/CHANGELOG.md @@ -4,5 +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.1.1] - 2019-06-06 +- Bump `rand_core` version +- Adjust usage of `#[inline]` + ## [0.1.0] - 2018-10-17 - Pulled out of the Rand crate diff --git a/rand_hc/Cargo.toml b/rand_hc/Cargo.toml index 8195ea9b733..7b1eb8096d7 100644 --- a/rand_hc/Cargo.toml +++ b/rand_hc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_hc" -version = "0.1.0" +version = "0.1.1" authors = ["The Rand Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" @@ -18,4 +18,4 @@ travis-ci = { repository = "rust-random/rand" } appveyor = { repository = "rust-random/rand" } [dependencies] -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } diff --git a/rand_hc/README.md b/rand_hc/README.md index d684195d183..36449c0c826 100644 --- a/rand_hc/README.md +++ b/rand_hc/README.md @@ -19,7 +19,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_hc) - [API documentation (docs.rs)](https://docs.rs/rand_hc) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_hc/CHANGELOG.md) [rand]: https://crates.io/crates/rand [^1]: Hongjun Wu (2008). ["The Stream Cipher HC-128"]( diff --git a/rand_hc/src/hc128.rs b/rand_hc/src/hc128.rs index 6c55ec029f4..a320f48f441 100644 --- a/rand_hc/src/hc128.rs +++ b/rand_hc/src/hc128.rs @@ -67,20 +67,22 @@ const SEED_WORDS: usize = 8; // 128 bit key followed by 128 bit iv pub struct Hc128Rng(BlockRng); impl RngCore for Hc128Rng { - #[inline(always)] + #[inline] fn next_u32(&mut self) -> u32 { self.0.next_u32() } - #[inline(always)] + #[inline] fn next_u64(&mut self) -> u64 { self.0.next_u64() } + #[inline] fn fill_bytes(&mut self, dest: &mut [u8]) { self.0.fill_bytes(dest) } + #[inline] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { self.0.try_fill_bytes(dest) } @@ -89,10 +91,12 @@ impl RngCore for Hc128Rng { impl SeedableRng for Hc128Rng { type Seed = ::Seed; + #[inline] fn from_seed(seed: Self::Seed) -> Self { Hc128Rng(BlockRng::::from_seed(seed)) } + #[inline] fn from_rng(rng: R) -> Result { BlockRng::::from_rng(rng).map(Hc128Rng) } @@ -268,6 +272,7 @@ impl Hc128Core { // Initialize an HC-128 random number generator. The seed has to be // 256 bits in length (`[u32; 8]`), matching the 128 bit `key` followed by // 128 bit `iv` when HC-128 where to be used as a stream cipher. + #[inline(always)] // single use: SeedableRng::from_seed fn init(seed: [u32; SEED_WORDS]) -> Self { #[inline] fn f1(x: u32) -> u32 { diff --git a/rand_isaac/CHANGELOG.md b/rand_isaac/CHANGELOG.md index fb1ab3f3c57..95de12a61f0 100644 --- a/rand_isaac/CHANGELOG.md +++ b/rand_isaac/CHANGELOG.md @@ -4,6 +4,11 @@ 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.1.2] - 2019-06-06 +- Bump `rand_core` version +- Remove deprecated code +- Adjust usage of `#[inline]` + ## [0.1.1] - 2018-11-26 - Fix `rand_core` version requirement - Fix doc links diff --git a/rand_isaac/Cargo.toml b/rand_isaac/Cargo.toml index 3624db80d18..63beeec70f9 100644 --- a/rand_isaac/Cargo.toml +++ b/rand_isaac/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_isaac" -version = "0.1.1" +version = "0.1.2" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" @@ -21,7 +21,7 @@ appveyor = { repository = "rust-random/rand" } serde1 = ["serde", "serde_derive", "rand_core/serde1"] [dependencies] -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } serde = { version = "1", optional = true } serde_derive = { version = "^1.0.38", optional = true } diff --git a/rand_isaac/README.md b/rand_isaac/README.md index 43ea02202d5..c16c63f3c4b 100644 --- a/rand_isaac/README.md +++ b/rand_isaac/README.md @@ -22,7 +22,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_isaac) - [API documentation (docs.rs)](https://docs.rs/rand_isaac) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_isaac/CHANGELOG.md) [rand]: https://crates.io/crates/rand [^1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number generator*](http://burtleburtle.net/bob/rand/isaacafa.html) diff --git a/rand_isaac/src/isaac.rs b/rand_isaac/src/isaac.rs index d584a4fd3a0..f857737a599 100644 --- a/rand_isaac/src/isaac.rs +++ b/rand_isaac/src/isaac.rs @@ -92,20 +92,22 @@ const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; pub struct IsaacRng(BlockRng); impl RngCore for IsaacRng { - #[inline(always)] + #[inline] fn next_u32(&mut self) -> u32 { self.0.next_u32() } - #[inline(always)] + #[inline] fn next_u64(&mut self) -> u64 { self.0.next_u64() } + #[inline] fn fill_bytes(&mut self, dest: &mut [u8]) { self.0.fill_bytes(dest) } + #[inline] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { self.0.try_fill_bytes(dest) } @@ -114,6 +116,7 @@ impl RngCore for IsaacRng { impl SeedableRng for IsaacRng { type Seed = ::Seed; + #[inline] fn from_seed(seed: Self::Seed) -> Self { IsaacRng(BlockRng::::from_seed(seed)) } @@ -121,10 +124,12 @@ impl SeedableRng for IsaacRng { /// Create an ISAAC random number generator using an `u64` as seed. /// If `seed == 0` this will produce the same stream of random numbers as /// the reference implementation when used unseeded. + #[inline] fn seed_from_u64(seed: u64) -> Self { IsaacRng(BlockRng::::seed_from_u64(seed)) } + #[inline] fn from_rng(rng: S) -> Result { BlockRng::::from_rng(rng).map(|rng| IsaacRng(rng)) } diff --git a/rand_isaac/src/isaac64.rs b/rand_isaac/src/isaac64.rs index f4cb3a0a1b3..902715ea934 100644 --- a/rand_isaac/src/isaac64.rs +++ b/rand_isaac/src/isaac64.rs @@ -83,20 +83,22 @@ const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; pub struct Isaac64Rng(BlockRng64); impl RngCore for Isaac64Rng { - #[inline(always)] + #[inline] fn next_u32(&mut self) -> u32 { self.0.next_u32() } - #[inline(always)] + #[inline] fn next_u64(&mut self) -> u64 { self.0.next_u64() } + #[inline] fn fill_bytes(&mut self, dest: &mut [u8]) { self.0.fill_bytes(dest) } + #[inline] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { self.0.try_fill_bytes(dest) } @@ -105,6 +107,7 @@ impl RngCore for Isaac64Rng { impl SeedableRng for Isaac64Rng { type Seed = ::Seed; + #[inline] fn from_seed(seed: Self::Seed) -> Self { Isaac64Rng(BlockRng64::::from_seed(seed)) } @@ -112,10 +115,12 @@ impl SeedableRng for Isaac64Rng { /// Create an ISAAC random number generator using an `u64` as seed. /// If `seed == 0` this will produce the same stream of random numbers as /// the reference implementation when used unseeded. + #[inline] fn seed_from_u64(seed: u64) -> Self { Isaac64Rng(BlockRng64::::seed_from_u64(seed)) } + #[inline] fn from_rng(rng: S) -> Result { BlockRng64::::from_rng(rng).map(|rng| Isaac64Rng(rng)) } diff --git a/rand_jitter/CHANGELOG.md b/rand_jitter/CHANGELOG.md index bbb21dcbf2f..9dd6c0a1ae6 100644 --- a/rand_jitter/CHANGELOG.md +++ b/rand_jitter/CHANGELOG.md @@ -4,6 +4,12 @@ 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.2.0] - 2019-06-06 +- Bump `rand_core` version +- Support new `Error` type in `rand_core` 0.5 +- Remove CryptoRng trait bound (#699, #814) +- Enable doc-testing of README + ## [0.1.4] - 2019-05-02 - Change error conversion code to partially fix #738 diff --git a/rand_jitter/Cargo.toml b/rand_jitter/Cargo.toml index d968ea4bd34..64cc523fa87 100644 --- a/rand_jitter/Cargo.toml +++ b/rand_jitter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_jitter" -version = "0.1.4" +version = "0.2.0" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -14,7 +14,7 @@ travis-ci = { repository = "rust-random/rand" } appveyor = { repository = "rust-random/rand" } [dependencies] -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } log = { version = "0.4", optional = true } [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] diff --git a/rand_jitter/README.md b/rand_jitter/README.md index f92ceeadabc..2091d6c3d29 100644 --- a/rand_jitter/README.md +++ b/rand_jitter/README.md @@ -24,7 +24,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_jitter) - [API documentation (docs.rs)](https://docs.rs/rand_jitter) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_jitter/CHANGELOG.md) ## Features diff --git a/rand_os/CHANGELOG.md b/rand_os/CHANGELOG.md index ddba15f968b..a9020f763e0 100644 --- a/rand_os/CHANGELOG.md +++ b/rand_os/CHANGELOG.md @@ -5,7 +5,7 @@ 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.2.0] - 2019-04-08 +## [0.2.0] - 2019-06-06 Replaced implementation with a backwards-compatible shim around [getrandom](https://crates.io/crates/getrandom). diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml index 402042a9b2d..ec81b6b4c3d 100644 --- a/rand_os/Cargo.toml +++ b/rand_os/Cargo.toml @@ -22,5 +22,5 @@ wasm-bindgen = ["getrandom/wasm-bindgen"] stdweb = ["getrandom/stdweb"] [dependencies] -rand_core = { path = "../rand_core", version = "0.4", features = ["std"] } +rand_core = { path = "../rand_core", version = "0.5", features = ["std"] } getrandom = "0.1.1" diff --git a/rand_os/README.md b/rand_os/README.md index ddfd1acbfb3..8ed8c50289a 100644 --- a/rand_os/README.md +++ b/rand_os/README.md @@ -22,7 +22,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_os) - [API documentation (docs.rs)](https://docs.rs/rand_os) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_os/CHANGELOG.md) ## License diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index 587aa5d7874..9c3d5016fc8 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -22,7 +22,7 @@ appveyor = { repository = "rust-random/rand" } serde1 = ["serde", "serde_derive"] [dependencies] -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } serde = { version = "1", optional = true } serde_derive = { version = "^1.0.38", optional = true } diff --git a/rand_pcg/README.md b/rand_pcg/README.md index e41bfb05c19..fe47f2d4161 100644 --- a/rand_pcg/README.md +++ b/rand_pcg/README.md @@ -24,7 +24,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_pcg) - [API documentation (docs.rs)](https://docs.rs/rand_pcg) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_pcg/CHANGELOG.md) ## Crate Features diff --git a/rand_xorshift/CHANGELOG.md b/rand_xorshift/CHANGELOG.md index 539af41313b..78abf6bf141 100644 --- a/rand_xorshift/CHANGELOG.md +++ b/rand_xorshift/CHANGELOG.md @@ -4,6 +4,10 @@ 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.1.2] - 2019-06-06 +- Bump `rand_core` version +- Make XorShiftRng::from_rng portable by enforcing Endianness (#815) + ## [0.1.1] - 2019-01-04 - Reorganise code and tests; tweak doc diff --git a/rand_xorshift/Cargo.toml b/rand_xorshift/Cargo.toml index 81b2d831efc..86ad39d65db 100644 --- a/rand_xorshift/Cargo.toml +++ b/rand_xorshift/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_xorshift" -version = "0.1.1" +version = "0.1.2" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" @@ -21,7 +21,7 @@ appveyor = { repository = "rust-random/rand" } serde1 = ["serde", "serde_derive"] [dependencies] -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } serde = { version = "1", optional = true } serde_derive = { version = "^1.0.38", optional = true } diff --git a/rand_xorshift/README.md b/rand_xorshift/README.md index e40923d5fa2..57de284be63 100644 --- a/rand_xorshift/README.md +++ b/rand_xorshift/README.md @@ -22,7 +22,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_xorshift) - [API documentation (docs.rs)](https://docs.rs/rand_xorshift) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_xorshift/CHANGELOG.md) [rand]: https://crates.io/crates/rand diff --git a/rand_xorshift/src/lib.rs b/rand_xorshift/src/lib.rs index db42ba2aa2a..f6301b1d60e 100644 --- a/rand_xorshift/src/lib.rs +++ b/rand_xorshift/src/lib.rs @@ -110,6 +110,10 @@ impl SeedableRng for XorShiftRng { let slice = slice::from_raw_parts_mut(ptr, 4 * 4); rng.try_fill_bytes(slice)?; } + for v in seed_u32.iter_mut() { + // enforce LE for consistency across platforms + *v = v.to_le(); + } if !seed_u32.iter().all(|&x| x == 0) { break; } } diff --git a/rand_xorshift/tests/mod.rs b/rand_xorshift/tests/mod.rs index 8374b64104a..32f6b941e84 100644 --- a/rand_xorshift/tests/mod.rs +++ b/rand_xorshift/tests/mod.rs @@ -12,9 +12,10 @@ fn test_xorshift_construction() { let mut rng1 = XorShiftRng::from_seed(seed); assert_eq!(rng1.next_u64(), 4325440999699518727); - let _rng2 = XorShiftRng::from_rng(rng1).unwrap(); - // Note: we cannot test the state of _rng2 because from_rng does not - // fix Endianness. This is allowed in the trait specification. + let mut rng2 = XorShiftRng::from_rng(&mut rng1).unwrap(); + // Yes, this makes rng2 a clone of rng1! + assert_eq!(rng1.next_u64(), 15614385950550801700); + assert_eq!(rng2.next_u64(), 15614385950550801700); } #[test] diff --git a/rand_xoshiro/CHANGELOG.md b/rand_xoshiro/CHANGELOG.md index 5b94416784a..8a32c6a8ba2 100644 --- a/rand_xoshiro/CHANGELOG.md +++ b/rand_xoshiro/CHANGELOG.md @@ -4,6 +4,10 @@ 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.2.1] - 2019-06-06 +- Bump `rand_core` version +- Document crate features in README + ## [0.2.0] - 2019-05-28 - Fix `seed_from_u64(0)` for `Xoroshiro64StarStar` and `Xoroshiro64Star`. This breaks value stability for these generators if initialized with `seed_from_u64`. diff --git a/rand_xoshiro/Cargo.toml b/rand_xoshiro/Cargo.toml index 6441badac17..94b0a297f3e 100644 --- a/rand_xoshiro/Cargo.toml +++ b/rand_xoshiro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_xoshiro" -version = "0.2.0" # NB: When modifying, also modify html_root_url in lib.rs +version = "0.2.1" # NB: When modifying, also modify html_root_url in lib.rs authors = ["The Rand Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" @@ -16,12 +16,11 @@ serde1 = ["serde", "serde_derive"] [dependencies] byteorder = { version = "1", default-features=false } -rand_core = { path = "../rand_core", version = "0.4" } +rand_core = { path = "../rand_core", version = "0.5" } serde = { version = "1", optional=true } serde_derive = { version = "^1.0.38", optional=true } [dev-dependencies] -rand = { path = "..", version = "0.6", default-features=false } # needed for doctests # This is for testing serde, unfortunately we can't specify feature-gated dev # deps yet, see: https://github.com/rust-lang/cargo/issues/1596 bincode = { version = "1" } diff --git a/rand_xoshiro/README.md b/rand_xoshiro/README.md index 97fc0dcaead..1c02992b2d7 100644 --- a/rand_xoshiro/README.md +++ b/rand_xoshiro/README.md @@ -17,7 +17,7 @@ Links: - [API documentation (master)](https://rust-random.github.io/rand/rand_xoshiro) - [API documentation (docs.rs)](https://docs.rs/rand_xoshiro) -- [Changelog](CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rand/blob/master/rand_xoshiro/CHANGELOG.md) ## Crate Features diff --git a/rand_xoshiro/src/lib.rs b/rand_xoshiro/src/lib.rs index b3f94ba6093..4ea92cb2c00 100644 --- a/rand_xoshiro/src/lib.rs +++ b/rand_xoshiro/src/lib.rs @@ -58,7 +58,7 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://docs.rs/rand_xoshiro/0.2.0")] + html_root_url = "https://docs.rs/rand_xoshiro/0.2.1")] #![deny(missing_docs)] #![deny(missing_debug_implementations)] diff --git a/rand_xoshiro/src/xoroshiro128plus.rs b/rand_xoshiro/src/xoroshiro128plus.rs index 297b2e553cb..2a3e09527dd 100644 --- a/rand_xoshiro/src/xoroshiro128plus.rs +++ b/rand_xoshiro/src/xoroshiro128plus.rs @@ -35,10 +35,9 @@ impl Xoroshiro128Plus { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128Plus; /// /// let rng1 = Xoroshiro128Plus::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoroshiro128starstar.rs b/rand_xoshiro/src/xoroshiro128starstar.rs index 427dc6d3c35..a15fc500156 100644 --- a/rand_xoshiro/src/xoroshiro128starstar.rs +++ b/rand_xoshiro/src/xoroshiro128starstar.rs @@ -34,10 +34,9 @@ impl Xoroshiro128StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128StarStar; /// /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoshiro128plus.rs b/rand_xoshiro/src/xoshiro128plus.rs index a4abefa487c..e24fa458a47 100644 --- a/rand_xoshiro/src/xoshiro128plus.rs +++ b/rand_xoshiro/src/xoshiro128plus.rs @@ -32,10 +32,9 @@ impl Xoshiro128Plus { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128StarStar; /// /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoshiro128starstar.rs b/rand_xoshiro/src/xoshiro128starstar.rs index 274f9caebc1..ee485f3922a 100644 --- a/rand_xoshiro/src/xoshiro128starstar.rs +++ b/rand_xoshiro/src/xoshiro128starstar.rs @@ -31,10 +31,9 @@ impl Xoshiro128StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128StarStar; /// /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoshiro256plus.rs b/rand_xoshiro/src/xoshiro256plus.rs index 4c6cbf99805..4e577b658de 100644 --- a/rand_xoshiro/src/xoshiro256plus.rs +++ b/rand_xoshiro/src/xoshiro256plus.rs @@ -32,10 +32,9 @@ impl Xoshiro256Plus { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro256Plus; /// /// let rng1 = Xoshiro256Plus::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoshiro256starstar.rs b/rand_xoshiro/src/xoshiro256starstar.rs index ac565877c78..1c2e83b1c01 100644 --- a/rand_xoshiro/src/xoshiro256starstar.rs +++ b/rand_xoshiro/src/xoshiro256starstar.rs @@ -31,10 +31,9 @@ impl Xoshiro256StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro256StarStar; /// /// let rng1 = Xoshiro256StarStar::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoshiro512plus.rs b/rand_xoshiro/src/xoshiro512plus.rs index ea2cb8f176e..bc4823ad278 100644 --- a/rand_xoshiro/src/xoshiro512plus.rs +++ b/rand_xoshiro/src/xoshiro512plus.rs @@ -34,10 +34,9 @@ impl Xoshiro512Plus { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro512Plus; /// /// let rng1 = Xoshiro512Plus::seed_from_u64(0); diff --git a/rand_xoshiro/src/xoshiro512starstar.rs b/rand_xoshiro/src/xoshiro512starstar.rs index c1215a5a1cc..3109f2b4ae4 100644 --- a/rand_xoshiro/src/xoshiro512starstar.rs +++ b/rand_xoshiro/src/xoshiro512starstar.rs @@ -33,10 +33,9 @@ impl Xoshiro512StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand; /// # extern crate rand_xoshiro; /// # fn main() { - /// use rand::SeedableRng; + /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro512StarStar; /// /// let rng1 = Xoshiro512StarStar::seed_from_u64(0); diff --git a/src/rngs/small.rs b/src/rngs/small.rs index 6a96338e802..1ffb2fbd8a8 100644 --- a/src/rngs/small.rs +++ b/src/rngs/small.rs @@ -89,10 +89,12 @@ impl RngCore for SmallRng { self.0.next_u64() } + #[inline(always)] fn fill_bytes(&mut self, dest: &mut [u8]) { self.0.fill_bytes(dest); } + #[inline(always)] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { self.0.try_fill_bytes(dest) } @@ -101,10 +103,12 @@ impl RngCore for SmallRng { impl SeedableRng for SmallRng { type Seed = ::Seed; + #[inline(always)] fn from_seed(seed: Self::Seed) -> Self { SmallRng(Rng::from_seed(seed)) } + #[inline(always)] fn from_rng(rng: R) -> Result { Rng::from_rng(rng).map(SmallRng) } diff --git a/src/rngs/std.rs b/src/rngs/std.rs index fe487786b1f..c9ea6ae84c0 100644 --- a/src/rngs/std.rs +++ b/src/rngs/std.rs @@ -44,10 +44,12 @@ impl RngCore for StdRng { self.0.next_u64() } + #[inline(always)] fn fill_bytes(&mut self, dest: &mut [u8]) { self.0.fill_bytes(dest); } + #[inline(always)] fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { self.0.try_fill_bytes(dest) } @@ -56,10 +58,12 @@ impl RngCore for StdRng { impl SeedableRng for StdRng { type Seed = ::Seed; + #[inline(always)] fn from_seed(seed: Self::Seed) -> Self { StdRng(Rng::from_seed(seed)) } + #[inline(always)] fn from_rng(rng: R) -> Result { Rng::from_rng(rng).map(StdRng) }