diff options
author | Haibo Huang <hhb@google.com> | 2021-01-11 21:04:46 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-01-11 21:04:46 +0000 |
commit | 368abbf977658a07b447c7d715920210aced3967 (patch) | |
tree | 0b1632da5b5b4cbce8ffd10f76d5817c6a1f28e5 | |
parent | fde400d2f5af4add9aa4303c33d9bd5273eeb050 (diff) | |
parent | 56ff62a9c82cfb122ae9d911af75ea43add3643a (diff) | |
download | rand_xorshift-368abbf977658a07b447c7d715920210aced3967.tar.gz |
Upgrade rust/crates/rand_xorshift to 0.3.0 am: 56ff62a9c8
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/rand_xorshift/+/1533726
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I8053008bee8ebd91c6c6dde4f45a9260200991fc
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | Cargo.toml | 20 | ||||
-rw-r--r-- | Cargo.toml.orig | 18 | ||||
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | src/lib.rs | 32 |
8 files changed, 42 insertions, 51 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 2619177..306696e 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "5610bdae3acdb0324f5636bb3e4a21e6324ead72" + "sha1": "eae0a9b91c5de272706134d25bc1ea3457bc9670" } } @@ -63,5 +63,5 @@ rust_test { // dependent_library ["feature_list"] // bincode-1.3.1 // byteorder-1.3.4 "default,std" -// rand_core-0.5.1 +// rand_core-0.6.0 // serde-1.0.118 "default,std" diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3098a..52367bd 100644 --- a/CHANGELOG.md +++ b/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.3.0] - 2020-12-18 +- Bump `rand_core` version to 0.6 (#17) +- Derive PartialEq+Eq for XorShiftRng (#6) +- Bump serde to 1.0.118 so that `serde1` feature can also be no-std (#12) + ## [0.2.0] - 2019-06-12 - Bump minor crate version since rand_core bump is a breaking change - Switch to Edition 2018 @@ -13,30 +13,26 @@ [package] edition = "2018" name = "rand_xorshift" -version = "0.2.0" +version = "0.3.0" authors = ["The Rand Project Developers", "The Rust Project Developers"] description = "Xorshift random number generator\n" -homepage = "https://crates.io/crates/rand_xorshift" -documentation = "https://rust-random.github.io/rand/rand_xorshift/" +homepage = "https://rust-random.github.io/book" +documentation = "https://docs.rs/rand_xorshift" readme = "README.md" keywords = ["random", "rng", "xorshift"] categories = ["algorithms", "no-std"] -license = "MIT/Apache-2.0" -repository = "https://github.com/rust-random/rand" +license = "MIT OR Apache-2.0" +repository = "https://github.com/rust-random/rngs" [dependencies.rand_core] -version = "0.5" +version = "0.6" [dependencies.serde] -version = "1" +version = "1.0.118" features = ["derive"] optional = true +default-features = false [dev-dependencies.bincode] version = "1" [features] serde1 = ["serde"] -[badges.appveyor] -repository = "rust-random/rand" - -[badges.travis-ci] -repository = "rust-random/rand" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index c47bcc9..78d3f5f 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,12 +1,12 @@ [package] name = "rand_xorshift" -version = "0.2.0" +version = "0.3.0" # NB: When modifying, also modify html_root_url in lib.rs authors = ["The Rand Project Developers", "The Rust Project Developers"] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_xorshift/" -homepage = "https://crates.io/crates/rand_xorshift" +repository = "https://github.com/rust-random/rngs" +documentation = "https://docs.rs/rand_xorshift" +homepage = "https://rust-random.github.io/book" description = """ Xorshift random number generator """ @@ -14,16 +14,12 @@ keywords = ["random", "rng", "xorshift"] categories = ["algorithms", "no-std"] edition = "2018" -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [features] serde1 = ["serde"] [dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -serde = { version = "1", features = ["derive"], optional = true } +rand_core = { version = "0.6" } +serde = { version = "1.0.118", default-features = false, features = ["derive"], optional = true } [dev-dependencies] # This is for testing serde, unfortunately we can't specify feature-gated dev @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/rand_xorshift/rand_xorshift-0.2.0.crate" + value: "https://static.crates.io/crates/rand_xorshift/rand_xorshift-0.3.0.crate" } - version: "0.2.0" + version: "0.3.0" license_type: NOTICE last_upgrade_date { year: 2020 month: 12 - day: 15 + day: 18 } } @@ -1,12 +1,12 @@ # rand_xorshift -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Build Status](https://travis-ci.org/rust-random/rngs.svg)](https://travis-ci.org/rust-random/rngs) +[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rngs?svg=true)](https://ci.appveyor.com/project/rust-random/rngs) [![Latest version](https://img.shields.io/crates/v/rand_xorshift.svg)](https://crates.io/crates/rand_xorshift) [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_xorshift) [![API](https://docs.rs/rand_xorshift/badge.svg)](https://docs.rs/rand_xorshift) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rngs#rust-version-requirements) Implements the Xorshift random number generator. @@ -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](https://github.com/rust-random/rand/blob/master/rand_xorshift/CHANGELOG.md) +- [Changelog](https://github.com/rust-random/rngs/blob/master/rand_xorshift/CHANGELOG.md) [rand]: https://crates.io/crates/rand @@ -10,7 +10,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://rust-random.github.io/rand/")] + html_root_url = "https://docs.rs/rand_xorshift/0.3.0")] #![deny(missing_docs)] #![deny(missing_debug_implementations)] @@ -18,7 +18,7 @@ #![no_std] use core::num::Wrapping as w; -use core::{fmt, slice}; +use core::fmt; use rand_core::{RngCore, SeedableRng, Error, impls, le}; #[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; @@ -31,7 +31,7 @@ use rand_core::{RngCore, SeedableRng, Error, impls, le}; /// [^1]: Marsaglia, George (July 2003). /// ["Xorshift RNGs"](https://www.jstatsoft.org/v08/i14/paper). /// *Journal of Statistical Software*. Vol. 8 (Issue 14). -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature="serde1", derive(Serialize,Deserialize))] pub struct XorShiftRng { x: w<u32>, @@ -71,7 +71,8 @@ impl RngCore for XorShiftRng { } fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - Ok(self.fill_bytes(dest)) + self.fill_bytes(dest); + Ok(()) } } @@ -98,26 +99,19 @@ impl SeedableRng for XorShiftRng { } fn from_rng<R: RngCore>(mut rng: R) -> Result<Self, Error> { - let mut seed_u32 = [0u32; 4]; + let mut b = [0u8; 16]; loop { - unsafe { - let ptr = seed_u32.as_mut_ptr() as *mut u8; - - let slice = slice::from_raw_parts_mut(ptr, 4 * 4); - rng.try_fill_bytes(slice)?; + rng.try_fill_bytes(&mut b[..])?; + if !b.iter().all(|&x| x == 0) { + break; } - 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; } } Ok(XorShiftRng { - x: w(seed_u32[0]), - y: w(seed_u32[1]), - z: w(seed_u32[2]), - w: w(seed_u32[3]), + x: w(u32::from_le_bytes([b[0], b[1], b[2], b[3]])), + y: w(u32::from_le_bytes([b[4], b[5], b[6], b[7]])), + z: w(u32::from_le_bytes([b[8], b[9], b[10], b[11]])), + w: w(u32::from_le_bytes([b[12], b[13], b[14], b[15]])), }) } } |