@@ -194,14 +194,14 @@ in the same range.
194194``` rust
195195extern crate rand;
196196
197- use rand :: distributions :: {Range , IndependentSample };
197+ use rand :: distributions :: {Range , Distribution };
198198
199199fn main () {
200200 let mut rng = rand :: thread_rng ();
201201 let die = Range :: new (1 , 7 );
202202
203203 loop {
204- let throw = die . ind_sample (& mut rng );
204+ let throw = die . sample (& mut rng );
205205 println! (" Roll the die: {}" , throw );
206206 if throw == 6 {
207207 break ;
@@ -221,7 +221,7 @@ fn main() {
221221By default, random numbers are generated with [ uniform distribution] .
222222To generate numbers with other distributions you instantiate a
223223distribution, then sample from that distribution using
224- [ ` IndependentSample::ind_sample ` ] with help of a random-number
224+ [ ` Distribution::sample ` ] with help of a random-number
225225generator [ ` rand::Rng ` ] .
226226
227227The [ distributions available are documented here] [ rand-distributions ] . An example using the
@@ -230,14 +230,14 @@ The [distributions available are documented here][rand-distributions]. An exampl
230230``` rust
231231extern crate rand;
232232
233- use rand :: distributions :: {Normal , IndependentSample };
233+ use rand :: distributions :: {Normal , Distribution };
234234
235235fn main () {
236236 let mut rng = rand :: thread_rng ();
237237
238238 // mean 2, standard deviation 3:
239239 let normal = Normal :: new (2.0 , 3.0 );
240- let v = normal . ind_sample (& mut rng );
240+ let v = normal . sample (& mut rng );
241241 println! (" {} is from a N(2, 9) distribution" , v )
242242}
243243```
@@ -249,21 +249,22 @@ fn main() {
249249[ ![ rand-badge]] [ rand ] [ ![ cat-science-badge]] [ cat-science ]
250250
251251Randomly generates a tuple ` (i32, bool, f64) ` and variable of user defined type ` Point ` .
252- Implements the [ ` rand::Rand ` ] trait for ` Point ` in order to allow random generation.
252+ Implements the [ ` Distribution ` ] trait on type ` Point ` for [ ` Standard ` ] in order to allow random generation.
253253
254254``` rust
255255extern crate rand;
256256
257- use rand :: {Rng , Rand };
257+ use rand :: Rng ;
258+ use rand :: distributions :: {Distribution , Standard };
258259
259260#[derive(Debug )]
260261struct Point {
261262 x : i32 ,
262263 y : i32 ,
263264}
264265
265- impl Rand for Point {
266- fn rand <R : Rng >( rng : & mut R ) -> Point {
266+ impl Distribution < Point > for Standard {
267+ fn sample <R : Rng + ? Sized >( & self , rng : & mut R ) -> Point {
267268 let (rand_x , rand_y ) = rng . gen ();
268269 Point {
269270 x : rand_x ,
@@ -287,15 +288,20 @@ fn main() {
287288
288289[ ![ rand-badge]] [ rand ] [ ![ cat-os-badge]] [ cat-os ]
289290
290- Randomly generates a string of given length ASCII characters in the range ` A-Z, a-z, 0-9 ` , with [ ` gen_ascii_chars ` ] .
291+ Randomly generates a string of given length ASCII characters in the range ` A-Z, a-z, 0-9 ` , with [ ` Alphanumeric ` ] sample .
291292
292293``` rust
293294extern crate rand;
294295
295296use rand :: {thread_rng, Rng };
297+ use rand :: distributions :: Alphanumeric ;
296298
297299fn main () {
298- let rand_string : String = thread_rng (). gen_ascii_chars (). take (30 ). collect ();
300+ let rand_string : String = thread_rng ()
301+ . sample_iter (& Alphanumeric )
302+ . take (30 )
303+ . collect ();
304+
299305 println! (" {}" , rand_string );
300306}
301307```
@@ -1806,10 +1812,10 @@ fn run() -> Result<()> {
18061812[ `foreign_links` ] : https://docs.rs/error-chain/*/error_chain/#foreign-links
18071813[ `fs::Metadata` ] : https://doc.rust-lang.org/std/fs/struct.Metadata.html
18081814[ `fs::read_dir` ] : https://doc.rust-lang.org/std/fs/fn.read_dir.html
1809- [ `gen_ascii_chars ` ] : https://docs.rs/rand/*/rand/trait.Rng .html#method.gen_ascii_chars
1815+ [ `Alphanumeric ` ] : https://docs.rs/rand/*/rand/distributions/struct.Alphanumeric .html#struct.Alphanumaric
18101816[ `HashMap` ] : https://doc.rust-lang.org/std/collections/struct.HashMap.html
18111817[ `hmac::Signature` ] : https://briansmith.org/rustdoc/ring/hmac/struct.Signature.html
1812- [ `IndependentSample::ind_sample ` ] : https://docs.rs/rand/*/rand/distributions/trait.IndependentSample .html#tymethod.ind_sample
1818+ [ `Distribution::sample ` ] : https://docs.rs/rand/*/rand/distributions/trait.Distribution .html#tymethod.sample
18131819[ `Lines` ] : https://doc.rust-lang.org/std/io/struct.Lines.html
18141820[ `Metadata::is_file` ] : https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.is_file
18151821[ `Metadata::modified` ] : https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.modified
@@ -1831,11 +1837,11 @@ fn run() -> Result<()> {
18311837[ `pbkdf2::derive` ] : https://briansmith.org/rustdoc/ring/pbkdf2/fn.derive.html
18321838[ `pbkdf2::verify` ] : https://briansmith.org/rustdoc/ring/pbkdf2/fn.verify.html
18331839[ `process::Stdio` ] : https://doc.rust-lang.org/std/process/struct.Stdio.html
1834- [ `rand::Rand` ] : https://docs.rs/rand/*/rand/trait.Rand.html
1835- [ `rand::Rand` ] : https://docs.rs/rand/*/rand/trait.Rand.html
18361840[ `rand::Rng` ] : https://docs.rs/rand/*/rand/trait.Rng.html
18371841[ `rand::thread_rng` ] : https://docs.rs/rand/*/rand/fn.thread_rng.html
1838- [ `Range` ] : https://docs.rs/rand/*/rand/distributions/range/struct.Range.html
1842+ [ `Range` ] : https://docs.rs/rand/*/rand/distributions/#reexports
1843+ [ `Standard` ] : https://docs.rs/rand/*/rand/distributions/struct.Standard.html
1844+ [ `Distribution` ] : https://docs.rs/rand/*/rand/distributions/trait.Distribution.html
18391845[ `Read` ] : https://doc.rust-lang.org/std/io/trait.Read.html
18401846[ `Regex::captures_iter` ] : https://doc.rust-lang.org/regex/*/regex/struct.Regex.html#method.captures_iter
18411847[ `regex::RegexSet` ] : https://doc.rust-lang.org/regex/*/regex/struct.RegexSet.html
0 commit comments