@@ -143,17 +143,6 @@ pub trait Rng : Sized {
143
143
/// with new data, and may panic if this is impossible
144
144
/// (e.g. reading past the end of a file that is being used as the
145
145
/// source of randomness).
146
- ///
147
- /// # Examples
148
- ///
149
- /// ```
150
- /// # #![feature(rand, core)]
151
- /// use std::rand::{thread_rng, Rng};
152
- ///
153
- /// let mut v = [0; 13579];
154
- /// thread_rng().fill_bytes(&mut v);
155
- /// println!("{:?}", &v[..]);
156
- /// ```
157
146
fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
158
147
// this could, in theory, be done by transmuting dest to a
159
148
// [u64], but this is (1) likely to be undefined behaviour for
@@ -179,38 +168,13 @@ pub trait Rng : Sized {
179
168
}
180
169
181
170
/// Return a random value of a `Rand` type.
182
- ///
183
- /// # Examples
184
- ///
185
- /// ```
186
- /// # #![feature(rand)]
187
- /// use std::rand::{thread_rng, Rng};
188
- ///
189
- /// let mut rng = thread_rng();
190
- /// let x: usize = rng.gen();
191
- /// println!("{}", x);
192
- /// println!("{:?}", rng.gen::<(f64, bool)>());
193
- /// ```
194
171
#[ inline( always) ]
195
172
fn gen < T : Rand > ( & mut self ) -> T {
196
173
Rand :: rand ( self )
197
174
}
198
175
199
176
/// Return an iterator that will yield an infinite number of randomly
200
177
/// generated items.
201
- ///
202
- /// # Examples
203
- ///
204
- /// ```
205
- /// # #![feature(rand)]
206
- /// use std::rand::{thread_rng, Rng};
207
- ///
208
- /// let mut rng = thread_rng();
209
- /// let x = rng.gen_iter::<usize>().take(10).collect::<Vec<usize>>();
210
- /// println!("{:?}", x);
211
- /// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5)
212
- /// .collect::<Vec<(f64, bool)>>());
213
- /// ```
214
178
fn gen_iter < ' a , T : Rand > ( & ' a mut self ) -> Generator < ' a , T , Self > {
215
179
Generator { rng : self , _marker : PhantomData }
216
180
}
@@ -226,69 +190,24 @@ pub trait Rng : Sized {
226
190
/// # Panics
227
191
///
228
192
/// Panics if `low >= high`.
229
- ///
230
- /// # Examples
231
- ///
232
- /// ```
233
- /// # #![feature(rand)]
234
- /// use std::rand::{thread_rng, Rng};
235
- ///
236
- /// let mut rng = thread_rng();
237
- /// let n: usize = rng.gen_range(0, 10);
238
- /// println!("{}", n);
239
- /// let m: f64 = rng.gen_range(-40.0f64, 1.3e5f64);
240
- /// println!("{}", m);
241
- /// ```
242
193
fn gen_range < T : PartialOrd + SampleRange > ( & mut self , low : T , high : T ) -> T {
243
194
assert ! ( low < high, "Rng.gen_range called with low >= high" ) ;
244
195
Range :: new ( low, high) . ind_sample ( self )
245
196
}
246
197
247
198
/// Return a bool with a 1 in n chance of true
248
- ///
249
- /// # Examples
250
- ///
251
- /// ```
252
- /// # #![feature(rand)]
253
- /// use std::rand::{thread_rng, Rng};
254
- ///
255
- /// let mut rng = thread_rng();
256
- /// println!("{}", rng.gen_weighted_bool(3));
257
- /// ```
258
199
fn gen_weighted_bool ( & mut self , n : usize ) -> bool {
259
200
n <= 1 || self . gen_range ( 0 , n) == 0
260
201
}
261
202
262
203
/// Return an iterator of random characters from the set A-Z,a-z,0-9.
263
- ///
264
- /// # Examples
265
- ///
266
- /// ```
267
- /// # #![feature(rand)]
268
- /// use std::rand::{thread_rng, Rng};
269
- ///
270
- /// let s: String = thread_rng().gen_ascii_chars().take(10).collect();
271
- /// println!("{}", s);
272
- /// ```
273
204
fn gen_ascii_chars < ' a > ( & ' a mut self ) -> AsciiGenerator < ' a , Self > {
274
205
AsciiGenerator { rng : self }
275
206
}
276
207
277
208
/// Return a random element from `values`.
278
209
///
279
210
/// Return `None` if `values` is empty.
280
- ///
281
- /// # Examples
282
- ///
283
- /// ```
284
- /// # #![feature(rand)]
285
- /// use std::rand::{thread_rng, Rng};
286
- ///
287
- /// let choices = [1, 2, 4, 8, 16, 32];
288
- /// let mut rng = thread_rng();
289
- /// println!("{:?}", rng.choose(&choices));
290
- /// assert_eq!(rng.choose(&choices[..0]), None);
291
- /// ```
292
211
fn choose < ' a , T > ( & mut self , values : & ' a [ T ] ) -> Option < & ' a T > {
293
212
if values. is_empty ( ) {
294
213
None
@@ -298,20 +217,6 @@ pub trait Rng : Sized {
298
217
}
299
218
300
219
/// Shuffle a mutable slice in place.
301
- ///
302
- /// # Examples
303
- ///
304
- /// ```
305
- /// # #![feature(rand, core)]
306
- /// use std::rand::{thread_rng, Rng};
307
- ///
308
- /// let mut rng = thread_rng();
309
- /// let mut y = [1, 2, 3];
310
- /// rng.shuffle(&mut y);
311
- /// println!("{:?}", y);
312
- /// rng.shuffle(&mut y);
313
- /// println!("{:?}", y);
314
- /// ```
315
220
fn shuffle < T > ( & mut self , values : & mut [ T ] ) {
316
221
let mut i = values. len ( ) ;
317
222
while i >= 2 {
@@ -362,33 +267,9 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
362
267
/// the same stream of randomness multiple times.
363
268
pub trait SeedableRng < Seed > : Rng {
364
269
/// Reseed an RNG with the given seed.
365
- ///
366
- /// # Examples
367
- ///
368
- /// ```
369
- /// # #![feature(rand)]
370
- /// use std::rand::{Rng, SeedableRng, StdRng};
371
- ///
372
- /// let seed: &[_] = &[1, 2, 3, 4];
373
- /// let mut rng: StdRng = SeedableRng::from_seed(seed);
374
- /// println!("{}", rng.gen::<f64>());
375
- /// rng.reseed(&[5, 6, 7, 8]);
376
- /// println!("{}", rng.gen::<f64>());
377
- /// ```
378
270
fn reseed ( & mut self , Seed ) ;
379
271
380
272
/// Create a new RNG with the given seed.
381
- ///
382
- /// # Examples
383
- ///
384
- /// ```
385
- /// # #![feature(rand)]
386
- /// use std::rand::{Rng, SeedableRng, StdRng};
387
- ///
388
- /// let seed: &[_] = &[1, 2, 3, 4];
389
- /// let mut rng: StdRng = SeedableRng::from_seed(seed);
390
- /// println!("{}", rng.gen::<f64>());
391
- /// ```
392
273
fn from_seed ( seed : Seed ) -> Self ;
393
274
}
394
275
@@ -484,16 +365,6 @@ impl Rand for XorShiftRng {
484
365
/// Use `Closed01` for the closed interval `[0,1]`, and the default
485
366
/// `Rand` implementation for `f32` and `f64` for the half-open
486
367
/// `[0,1)`.
487
- ///
488
- /// # Examples
489
- ///
490
- /// ```
491
- /// # #![feature(rand)]
492
- /// use std::rand::{random, Open01};
493
- ///
494
- /// let Open01(val) = random::<Open01<f32>>();
495
- /// println!("f32 from (0,1): {}", val);
496
- /// ```
497
368
pub struct Open01 < F > ( pub F ) ;
498
369
499
370
/// A wrapper for generating floating point numbers uniformly in the
@@ -502,16 +373,6 @@ pub struct Open01<F>(pub F);
502
373
/// Use `Open01` for the closed interval `(0,1)`, and the default
503
374
/// `Rand` implementation of `f32` and `f64` for the half-open
504
375
/// `[0,1)`.
505
- ///
506
- /// # Examples
507
- ///
508
- /// ```
509
- /// # #![feature(rand)]
510
- /// use std::rand::{random, Closed01};
511
- ///
512
- /// let Closed01(val) = random::<Closed01<f32>>();
513
- /// println!("f32 from [0,1]: {}", val);
514
- /// ```
515
376
pub struct Closed01 < F > ( pub F ) ;
516
377
517
378
#[ cfg( test) ]
0 commit comments