diff --git a/Cargo.toml b/Cargo.toml index 5d368e18c..eb6bfd21f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,10 @@ status = "actively-developed" [badges.travis-ci] repository = "uuid-rs/uuid" +[dependencies.getrandom] +optional = true +version = "0.1" + [dependencies.md5] optional = true version = "0.7" @@ -95,7 +99,7 @@ std = [] stdweb = [ "rand/stdweb" ] v1 = [] v3 = ["md5"] -v4 = ["rand"] +v4 = ["getrandom"] v5 = ["sha1"] wasm-bindgen = ["rand/wasm-bindgen"] diff --git a/src/v4.rs b/src/v4.rs index fe1af0f63..d6cd70b48 100644 --- a/src/v4.rs +++ b/src/v4.rs @@ -1,5 +1,4 @@ use crate::prelude::*; -use rand; impl Uuid { /// Creates a random UUID. @@ -23,12 +22,8 @@ impl Uuid { /// /// [`rand`]: https://crates.io/crates/rand pub fn new_v4() -> Self { - use rand::RngCore; - - let mut rng = rand::thread_rng(); let mut bytes = [0; 16]; - - rng.fill_bytes(&mut bytes); + getrandom::getrandom(&mut bytes).expect("RNG failure!"); Builder::from_bytes(bytes) .set_variant(Variant::RFC4122)