Skip to content

Fixed the examples in stdlib/rand.rs #7693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions src/libstd/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ distributions like normal and exponential.
# Examples

~~~ {.rust}
use core::rand::RngUtil;
use std::rand;
use std::rand::RngUtil;

fn main() {
let mut rng = rand::rng();
Expand All @@ -33,6 +34,8 @@ fn main() {
~~~

~~~ {.rust}
use std::rand;

fn main () {
let tuple_ptr = rand::random::<~(f64, char)>();
println(fmt!("%?", tuple_ptr))
Expand Down Expand Up @@ -292,10 +295,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* println(fmt!("%b",rng.gen_weighted_bool(3)));
* }
* ~~~
Expand All @@ -308,10 +312,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* println(rng.gen_str(8));
* }
* ~~~
Expand All @@ -324,10 +329,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* println(fmt!("%?",rng.gen_bytes(8)));
* }
* ~~~
Expand All @@ -340,10 +346,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* println(fmt!("%d",rng.choose([1,2,4,8,16,32])));
* }
* ~~~
Expand All @@ -359,10 +366,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* let x = [rand::Weighted {weight: 4, item: 'a'},
* rand::Weighted {weight: 2, item: 'b'},
* rand::Weighted {weight: 2, item: 'c'}];
Expand All @@ -379,10 +387,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* let x = [rand::Weighted {weight: 4, item: 'a'},
* rand::Weighted {weight: 2, item: 'b'},
* rand::Weighted {weight: 2, item: 'c'}];
Expand All @@ -400,10 +409,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* let x = [rand::Weighted {weight: 4, item: 'a'},
* rand::Weighted {weight: 2, item: 'b'},
* rand::Weighted {weight: 2, item: 'c'}];
Expand All @@ -419,10 +429,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* println(fmt!("%?",rng.shuffle([1,2,3])));
* }
* ~~~
Expand All @@ -435,10 +446,11 @@ pub trait RngUtil {
*
* ~~~ {.rust}
*
* use core::rand::RngUtil;
* use std::rand;
* use std::rand::RngUtil;
*
* fn main() {
* rng = rand::rng();
* let mut rng = rand::rng();
* let mut y = [1,2,3];
* rng.shuffle_mut(y);
* println(fmt!("%?",y));
Expand Down