Change to PCG random number generator algorithm

See http://www.pcg-random.org/ for benefits of PCG over xorshift
Updates #236 #183
This commit is contained in:
ice_iix 2020-01-05 10:01:44 -08:00
parent 6c32fce5a3
commit b307843d2b
4 changed files with 15 additions and 15 deletions

20
Cargo.lock generated
View File

@ -1630,6 +1630,14 @@ dependencies = [
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_pcg"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_xorshift"
version = "0.1.1"
@ -1638,14 +1646,6 @@ dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_xorshift"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rayon"
version = "1.3.0"
@ -2084,7 +2084,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rsa_public_encrypt_pkcs1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2947,8 +2947,8 @@ dependencies = [
"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
"checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
"checksum rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8"
"checksum rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098"
"checksum rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"

View File

@ -32,7 +32,7 @@ flate2 = { version = "1.0.13", features = ["rust_backend"], default-features = f
zip = { version = "0.5.3", features = ["deflate"], default-features = false }
image = "0.22.3"
rand = "0.7.2"
rand_xorshift = "0.2.0"
rand_pcg = "0.2.1"
hex = "0.4.0"
base64 = "0.11.0"
log = { version = "0.4.8", features = ["std"] }

View File

@ -10,7 +10,7 @@ use crate::model;
use crate::types::bit::Set;
use crate::shared::Direction;
use rand::{self, SeedableRng, Rng};
use rand_xorshift;
use rand_pcg;
const NUM_WORKERS: usize = 8;
@ -122,7 +122,7 @@ fn build_func(id: usize, models: Arc<RwLock<model::Factory>>, work_recv: mpsc::R
Err(_) => return,
};
let mut rng = rand_xorshift::XorShiftRng::from_seed([
let mut rng = rand_pcg::Pcg32::from_seed([
((position.0 as u32) & 0xff) as u8,
(((position.0 as u32) >> 8) & 0xff) as u8,
(((position.0 as u32) >> 16) & 0xff) as u8,

View File

@ -6,7 +6,7 @@ use crate::render;
use crate::resources;
use std::time::{SystemTime, UNIX_EPOCH};
use rand::{self, seq::SliceRandom};
use rand_xorshift;
use rand_pcg;
pub struct Logo {
_shadow: ui::BatchRef,
@ -101,7 +101,7 @@ impl Logo {
text_strings.push(line.to_owned().replace("\r", ""));
}
}
let mut r: rand_xorshift::XorShiftRng = rand::SeedableRng::from_seed([45, 0, 0, 0, 64, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0]);
let mut r: rand_pcg::Pcg32 = rand::SeedableRng::from_seed([45, 0, 0, 0, 64, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0]);
text_strings.shuffle(&mut r);
}