diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a300d36e..56244311 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -299,7 +299,7 @@ explanation in the description. > use rand::distributions::{Normal, Distribution}; > > fn main() { -> let mut rng = rand::thread_rng(); +> let mut rng = rand::rng(); > let normal = Normal::new(2.0, 3.0); > let v = normal.sample(&mut rng); > println!("{} is from a N(2, 9) distribution", v) diff --git a/Cargo.toml b/Cargo.toml index f0d49797..a0acf873 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,8 +36,8 @@ num_cpus = "1.16" percent-encoding = "2.3" petgraph = "0.6" postgres = "0.19" -rand = "0.8" -rand_distr = "0.4" +rand = "0.9" +rand_distr = "0.5.1" rayon = "1.10" regex = "1.11" reqwest = { version = "0.12", features = ["blocking", "json", "stream"] } diff --git a/src/algorithms/randomness/rand-choose.md b/src/algorithms/randomness/rand-choose.md index 734f2661..5754915e 100644 --- a/src/algorithms/randomness/rand-choose.md +++ b/src/algorithms/randomness/rand-choose.md @@ -3,7 +3,7 @@ [![rand-badge]][rand] [![cat-os-badge]][cat-os] Randomly generates a string of given length ASCII characters with custom -user-defined bytestring, with [`gen_range`]. +user-defined bytestring, with [`random_range`]. ```rust,edition2018 fn main() { @@ -12,11 +12,11 @@ fn main() { abcdefghijklmnopqrstuvwxyz\ 0123456789)(*&^%$#@!~"; const PASSWORD_LEN: usize = 30; - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let password: String = (0..PASSWORD_LEN) .map(|_| { - let idx = rng.gen_range(0..CHARSET.len()); + let idx = rng.random_range(0..CHARSET.len()); CHARSET[idx] as char }) .collect(); @@ -25,4 +25,4 @@ fn main() { } ``` -[`gen_range`]: https://docs.rs/rand/*/rand/trait.Rng.html#method.gen_range +[`random_range`]: https://docs.rs/rand/*/rand/trait.Rng.html#method.random_range diff --git a/src/algorithms/randomness/rand-custom.md b/src/algorithms/randomness/rand-custom.md index 94404da6..33fd238c 100644 --- a/src/algorithms/randomness/rand-custom.md +++ b/src/algorithms/randomness/rand-custom.md @@ -17,7 +17,7 @@ struct Point { impl Distribution for Standard { fn sample(&self, rng: &mut R) -> Point { - let (rand_x, rand_y) = rng.gen(); + let (rand_x, rand_y) = rng.random(); Point { x: rand_x, y: rand_y, @@ -26,9 +26,9 @@ impl Distribution for Standard { } fn main() { - let mut rng = rand::thread_rng(); - let rand_tuple = rng.gen::<(i32, bool, f64)>(); - let rand_point: Point = rng.gen(); + let mut rng = rand::rng(); + let rand_tuple = rng.random::<(i32, bool, f64)>(); + let rand_point: Point = rng.random(); println!("Random tuple: {:?}", rand_tuple); println!("Random Point: {:?}", rand_point); } diff --git a/src/algorithms/randomness/rand-dist.md b/src/algorithms/randomness/rand-dist.md index 7ed62162..35efe31c 100644 --- a/src/algorithms/randomness/rand-dist.md +++ b/src/algorithms/randomness/rand-dist.md @@ -14,10 +14,10 @@ An example using the [`Normal`] distribution is shown below. ```rust,edition2018,ignore use rand_distr::{Distribution, Normal, NormalError}; -use rand::thread_rng; +use rand::rng; fn main() -> Result<(), NormalError> { - let mut rng = thread_rng(); + let mut rng = rng(); let normal = Normal::new(2.0, 3.0)?; let v = normal.sample(&mut rng); println!("{} is from a N(2, 9) distribution", v); diff --git a/src/algorithms/randomness/rand-passwd.md b/src/algorithms/randomness/rand-passwd.md index e8c78634..8c74662e 100644 --- a/src/algorithms/randomness/rand-passwd.md +++ b/src/algorithms/randomness/rand-passwd.md @@ -6,11 +6,11 @@ Randomly generates a string of given length ASCII characters in the range `A-Z, a-z, 0-9`, with [`Alphanumeric`] sample. ```rust,edition2018 -use rand::{thread_rng, Rng}; +use rand::{rng, Rng}; use rand::distributions::Alphanumeric; fn main() { - let rand_string: String = thread_rng() + let rand_string: String = rng() .sample_iter(&Alphanumeric) .take(30) .map(char::from) diff --git a/src/algorithms/randomness/rand-range.md b/src/algorithms/randomness/rand-range.md index 9dc60651..acae3475 100644 --- a/src/algorithms/randomness/rand-range.md +++ b/src/algorithms/randomness/rand-range.md @@ -2,15 +2,15 @@ [![rand-badge]][rand] [![cat-science-badge]][cat-science] -Generates a random value within half-open `[0, 10)` range (not including `10`) with [`Rng::gen_range`]. +Generates a random value within half-open `[0, 10)` range (not including `10`) with [`Rng::random_range`]. ```rust,edition2018 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)); + let mut rng = rand::rng(); + println!("Integer: {}", rng.random_range(0..10)); + println!("Float: {}", rng.random_range(0.0..10.0)); } ``` @@ -23,7 +23,7 @@ in the same range. use rand::distributions::{Distribution, Uniform}; fn main() { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let die = Uniform::from(1..7); loop { @@ -37,5 +37,5 @@ fn main() { ``` [`Uniform`]: https://docs.rs/rand/*/rand/distributions/uniform/struct.Uniform.html -[`Rng::gen_range`]: https://doc.rust-lang.org/rand/*/rand/trait.Rng.html#method.gen_range +[`Rng::random_range`]: https://doc.rust-lang.org/rand/*/rand/trait.Rng.html#method.random_range [uniform distribution]: https://en.wikipedia.org/wiki/Uniform_distribution_(continuous) diff --git a/src/algorithms/randomness/rand.md b/src/algorithms/randomness/rand.md index 6a8724e5..4db33c89 100644 --- a/src/algorithms/randomness/rand.md +++ b/src/algorithms/randomness/rand.md @@ -3,7 +3,7 @@ [![rand-badge]][rand] [![cat-science-badge]][cat-science] Generates random numbers with help of random-number -generator [`rand::Rng`] obtained via [`rand::thread_rng`]. Each thread has an +generator [`rand::Rng`] obtained via [`rand::rng`]. Each thread has an initialized generator. Integers are uniformly distributed over the range of the type, and floating point numbers are uniformly distributed from 0 up to but not including 1. @@ -12,17 +12,17 @@ including 1. use rand::Rng; fn main() { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); - let n1: u8 = rng.gen(); - let n2: u16 = rng.gen(); + let n1: u8 = rng.random(); + let n2: u16 = rng.random(); println!("Random u8: {}", n1); println!("Random u16: {}", n2); - println!("Random u32: {}", rng.gen::()); - println!("Random i32: {}", rng.gen::()); - println!("Random float: {}", rng.gen::()); + println!("Random u32: {}", rng.random::()); + println!("Random i32: {}", rng.random::()); + println!("Random float: {}", rng.random::()); } ``` [`rand::Rng`]: https://docs.rs/rand/*/rand/trait.Rng.html -[`rand::thread_rng`]: https://docs.rs/rand/*/rand/fn.thread_rng.html +[`rand::rng`]: https://docs.rs/rand/*/rand/fn.rng.html