Skip to content

Commit

Permalink
Fixes rands
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Sep 19, 2019
1 parent e7c3aef commit 7c0d7f6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/algorithms/randomness/rand-choose.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ user-defined bytestring, with [`gen_range`].

```rust
extern crate rand;
use rand::{Rng, thread_rng};

fn main() {
use rand::Rng;
const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
0123456789)(*&^%$#@!~";
const PASSWORD_LEN: usize = 30;
let mut rng = rand::thread_rng();
let mut rng = thread_rng();

let password: String = (0..PASSWORD_LEN)
.map(|_| {
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/randomness/rand-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Implements the [`Distribution`] trait on type Point for [`Standard`] in order to
```rust
extern crate rand;

use rand::Rng;
use rand::{Rng, thread_rng};
use rand::distributions::{Distribution, Standard};

#[derive(Debug)]
Expand All @@ -28,7 +28,7 @@ impl Distribution<Point> for Standard {
}

fn main() {
let mut rng = rand::thread_rng();
let mut rng = thread_rng();
let rand_tuple = rng.gen::<(i32, bool, f64)>();
let rand_point: Point = rng.gen();
println!("Random tuple: {:?}", rand_tuple);
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/randomness/rand-dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ The [distributions available are documented here][rand-distributions]. An exampl

```rust
extern crate rand;

use rand::{Rng, thread_rng};
use rand::distributions::{Normal, Distribution};

fn main() {
let mut rng = rand::thread_rng();
let mut rng = thread_rng();
let normal = Normal::new(2.0, 3.0);
let v = normal.sample(&mut rng);
println!("{} is from a N(2, 9) distribution", v)
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/randomness/rand-passwd.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a-z, 0-9`, with [`Alphanumeric`] sample.
```rust
extern crate rand;

use rand::{thread_rng, Rng};
use rand::{Rng, thread_rng};
use rand::distributions::Alphanumeric;

fn main() {
Expand Down
5 changes: 2 additions & 3 deletions src/algorithms/randomness/rand-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ Generates a random value within half-open `[0, 10)` range (not including `10`) w

```rust
extern crate rand;

use rand::Rng;
use rand::{Rng, thread_rng};

fn main() {
let mut rng = rand::thread_rng();
let mut rng = thread_rng();
println!("Integer: {}", rng.gen_range(0, 10));
println!("Float: {}", rng.gen_range(0.0, 10.0));
}
Expand Down
5 changes: 2 additions & 3 deletions src/algorithms/randomness/rand.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ including 1.

```rust
extern crate rand;

use rand::Rng;
use rand::{Rng, thread_rng};

fn main() {
let mut rng = rand::thread_rng();
let mut rng = thread_rng();

let n1: u8 = rng.gen();
let n2: u16 = rng.gen();
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/parallel/rayon-parallel-sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
let mut vec = vec![String::new(); 100_000];
vec.par_iter_mut().for_each(|p| {
let mut rng = thread_rng();
*p = (0..5).map(|_| rng.sample(&Alphanumeric)).collect()
*p = rng.sample_iter(&Alphanumeric).take(5).collect()
});
vec.par_sort_unstable();
}
Expand Down

0 comments on commit 7c0d7f6

Please sign in to comment.