From 8d0d2e3fb1f26e4e79a914ea332096a0ba2ba2da Mon Sep 17 00:00:00 2001 From: Vegard Berg <162863+myrkvi@users.noreply.github.com> Date: Sat, 2 Jan 2021 00:24:59 +0100 Subject: [PATCH] Updated `rand_distr`, fixed and updated `rand`. (#627) The `rand` crate has been updated to version `0.8.0`, and has its code samples updated. The `rand_distr` crate has been updated to version `0.4.0`. --- Cargo.toml | 4 ++-- src/algorithms/randomness/rand-choose.md | 2 +- src/algorithms/randomness/rand-passwd.md | 1 + src/algorithms/randomness/rand-range.md | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e01325..ab2a4c7 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,8 +37,8 @@ num_cpus = "1.8" percent-encoding = "2.1" petgraph = "0.4" postgres = "0.17.2" -rand = "0.7.3" -rand_distr = "0.2.2" +rand = "0.8.0" +rand_distr = "0.4.0" rayon = "1.0" regex = "1.0" reqwest = { version = "0.10", features = ["blocking", "json", "stream"] } diff --git a/src/algorithms/randomness/rand-choose.md b/src/algorithms/randomness/rand-choose.md index b895139..734f266 100644 --- a/src/algorithms/randomness/rand-choose.md +++ b/src/algorithms/randomness/rand-choose.md @@ -16,7 +16,7 @@ fn main() { let password: String = (0..PASSWORD_LEN) .map(|_| { - let idx = rng.gen_range(0, CHARSET.len()); + let idx = rng.gen_range(0..CHARSET.len()); CHARSET[idx] as char }) .collect(); diff --git a/src/algorithms/randomness/rand-passwd.md b/src/algorithms/randomness/rand-passwd.md index 7d7ff86..e8c7863 100644 --- a/src/algorithms/randomness/rand-passwd.md +++ b/src/algorithms/randomness/rand-passwd.md @@ -13,6 +13,7 @@ fn main() { let rand_string: String = thread_rng() .sample_iter(&Alphanumeric) .take(30) + .map(char::from) .collect(); println!("{}", rand_string); diff --git a/src/algorithms/randomness/rand-range.md b/src/algorithms/randomness/rand-range.md index 6c4701e..9dc6065 100644 --- a/src/algorithms/randomness/rand-range.md +++ b/src/algorithms/randomness/rand-range.md @@ -9,8 +9,8 @@ use rand::Rng; fn main() { let mut rng = rand::thread_rng(); - println!("Integer: {}", rng.gen_range(0, 10)); - println!("Float: {}", rng.gen_range(0.0, 10.0)); + println!("Integer: {}", rng.gen_range(0..10)); + println!("Float: {}", rng.gen_range(0.0..10.0)); } ```