Skip to content

Commit ab2aa95

Browse files
committed
Wrapped up an example in README.md
1 parent 7bdc967 commit ab2aa95

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,28 @@ extern crate rand;
3535

3636
use rand::prelude::*;
3737

38-
// basic usage with random():
39-
let x: u8 = random();
40-
println!("{}", x);
41-
42-
let y = random::<f64>();
43-
println!("{}", y);
44-
45-
if random() { // generates a boolean
46-
println!("Heads!");
47-
}
48-
49-
// normal usage needs both an RNG and a function to generate the appropriate
50-
// type, range, distribution, etc.
51-
let mut rng = thread_rng();
52-
if rng.gen() { // random bool
53-
let x: f64 = rng.gen(); // random number in range (0, 1)
54-
println!("x is: {}", x);
55-
let ch = rng.gen::<char>(); // Sometimes you need type annotation
56-
println!("char is: {}", ch);
57-
println!("Number from 0 to 9: {}", rng.gen_range(0, 10));
38+
fn main() {
39+
// basic usage with random():
40+
let x: u8 = random();
41+
println!("{}", x);
42+
43+
let y = random::<f64>();
44+
println!("{}", y);
45+
46+
if random() { // generates a boolean
47+
println!("Heads!");
48+
}
49+
50+
// normal usage needs both an RNG and a function to generate the appropriate
51+
// type, range, distribution, etc.
52+
let mut rng = thread_rng();
53+
if rng.gen() { // random bool
54+
let x: f64 = rng.gen(); // random number in range (0, 1)
55+
println!("x is: {}", x);
56+
let ch = rng.gen::<char>(); // Sometimes you need type annotation
57+
println!("char is: {}", ch);
58+
println!("Number from 0 to 9: {}", rng.gen_range(0, 10));
59+
}
5860
}
5961
```
6062

0 commit comments

Comments
 (0)