@@ -194,14 +194,14 @@ in the same range.
194
194
``` rust
195
195
extern crate rand;
196
196
197
- use rand :: distributions :: {Range , IndependentSample };
197
+ use rand :: distributions :: {Range , Distribution };
198
198
199
199
fn main () {
200
200
let mut rng = rand :: thread_rng ();
201
201
let die = Range :: new (1 , 7 );
202
202
203
203
loop {
204
- let throw = die . ind_sample (& mut rng );
204
+ let throw = die . sample (& mut rng );
205
205
println! (" Roll the die: {}" , throw );
206
206
if throw == 6 {
207
207
break ;
@@ -221,7 +221,7 @@ fn main() {
221
221
By default, random numbers are generated with [ uniform distribution] .
222
222
To generate numbers with other distributions you instantiate a
223
223
distribution, 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
225
225
generator [ ` rand::Rng ` ] .
226
226
227
227
The [ 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
230
230
``` rust
231
231
extern crate rand;
232
232
233
- use rand :: distributions :: {Normal , IndependentSample };
233
+ use rand :: distributions :: {Normal , Distribution };
234
234
235
235
fn main () {
236
236
let mut rng = rand :: thread_rng ();
237
237
238
238
// mean 2, standard deviation 3:
239
239
let normal = Normal :: new (2.0 , 3.0 );
240
- let v = normal . ind_sample (& mut rng );
240
+ let v = normal . sample (& mut rng );
241
241
println! (" {} is from a N(2, 9) distribution" , v )
242
242
}
243
243
```
@@ -249,21 +249,22 @@ fn main() {
249
249
[ ![ rand-badge]] [ rand ] [ ![ cat-science-badge]] [ cat-science ]
250
250
251
251
Randomly 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.
253
253
254
254
``` rust
255
255
extern crate rand;
256
256
257
- use rand :: {Rng , Rand };
257
+ use rand :: Rng ;
258
+ use rand :: distributions :: {Distribution , Standard };
258
259
259
260
#[derive(Debug )]
260
261
struct Point {
261
262
x : i32 ,
262
263
y : i32 ,
263
264
}
264
265
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 {
267
268
let (rand_x , rand_y ) = rng . gen ();
268
269
Point {
269
270
x : rand_x ,
@@ -287,15 +288,20 @@ fn main() {
287
288
288
289
[ ![ rand-badge]] [ rand ] [ ![ cat-os-badge]] [ cat-os ]
289
290
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 .
291
292
292
293
``` rust
293
294
extern crate rand;
294
295
295
296
use rand :: {thread_rng, Rng };
297
+ use rand :: distributions :: Alphanumeric ;
296
298
297
299
fn 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
+
299
305
println! (" {}" , rand_string );
300
306
}
301
307
```
@@ -1806,10 +1812,10 @@ fn run() -> Result<()> {
1806
1812
[ `foreign_links` ] : https://docs.rs/error-chain/*/error_chain/#foreign-links
1807
1813
[ `fs::Metadata` ] : https://doc.rust-lang.org/std/fs/struct.Metadata.html
1808
1814
[ `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
1810
1816
[ `HashMap` ] : https://doc.rust-lang.org/std/collections/struct.HashMap.html
1811
1817
[ `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
1813
1819
[ `Lines` ] : https://doc.rust-lang.org/std/io/struct.Lines.html
1814
1820
[ `Metadata::is_file` ] : https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.is_file
1815
1821
[ `Metadata::modified` ] : https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.modified
@@ -1831,11 +1837,11 @@ fn run() -> Result<()> {
1831
1837
[ `pbkdf2::derive` ] : https://briansmith.org/rustdoc/ring/pbkdf2/fn.derive.html
1832
1838
[ `pbkdf2::verify` ] : https://briansmith.org/rustdoc/ring/pbkdf2/fn.verify.html
1833
1839
[ `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
1836
1840
[ `rand::Rng` ] : https://docs.rs/rand/*/rand/trait.Rng.html
1837
1841
[ `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
1839
1845
[ `Read` ] : https://doc.rust-lang.org/std/io/trait.Read.html
1840
1846
[ `Regex::captures_iter` ] : https://doc.rust-lang.org/regex/*/regex/struct.Regex.html#method.captures_iter
1841
1847
[ `regex::RegexSet` ] : https://doc.rust-lang.org/regex/*/regex/struct.RegexSet.html
0 commit comments