Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use getrandom to seed RNG #86

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ exclude = ["/.*"]
default = ["std"]
alloc = []
std = ["alloc"]
js = ["std", "getrandom"]
js = ["std", "getrandom/js"]

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"], optional = true }
[dependencies]
getrandom = "0.2"

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dev-dependencies]
wasm-bindgen-test = "0.3"
Expand Down
20 changes: 2 additions & 18 deletions src/global_rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,10 @@ pub fn choose_multiple<T: Iterator>(source: T, amount: usize) -> Vec<T::Item> {
}

#[cfg(not(all(
any(target_arch = "wasm32", target_arch = "wasm64"),
target_os = "unknown"
)))]
fn random_seed() -> Option<u64> {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::thread;
use std::time::Instant;

let mut hasher = DefaultHasher::new();
Instant::now().hash(&mut hasher);
thread::current().id().hash(&mut hasher);
Some(hasher.finish())
}

#[cfg(all(
any(target_arch = "wasm32", target_arch = "wasm64"),
target_os = "unknown",
feature = "js"
))]
not(feature = "js")
)))]
fn random_seed() -> Option<u64> {
// TODO(notgull): Failures should be logged somewhere.
let mut seed = [0u8; 8];
Expand Down
Loading