Skip to content

Commit 68953a4

Browse files
committed
Small doc polishing
1 parent 969af18 commit 68953a4

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

src/lib.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ use distributions::uniform::SampleUniform;
278278

279279
/// An automatically-implemented extension trait on [`RngCore`] providing high-level
280280
/// generic methods for sampling values and other convenience methods.
281-
///
281+
///
282282
/// This is the primary trait to use when generating random values.
283283
///
284284
/// # Generic usage
@@ -322,7 +322,7 @@ pub trait Rng: RngCore {
322322
///
323323
/// # Example
324324
///
325-
/// ```rust
325+
/// ```
326326
/// use rand::{thread_rng, Rng};
327327
///
328328
/// let mut rng = thread_rng();
@@ -351,7 +351,7 @@ pub trait Rng: RngCore {
351351
///
352352
/// # Example
353353
///
354-
/// ```rust
354+
/// ```
355355
/// use rand::{thread_rng, Rng};
356356
///
357357
/// let mut rng = thread_rng();
@@ -368,7 +368,7 @@ pub trait Rng: RngCore {
368368
///
369369
/// ### Example
370370
///
371-
/// ```rust
371+
/// ```
372372
/// use rand::{thread_rng, Rng};
373373
/// use rand::distributions::Uniform;
374374
///
@@ -383,7 +383,7 @@ pub trait Rng: RngCore {
383383
///
384384
/// # Example
385385
///
386-
/// ```rust
386+
/// ```
387387
/// use rand::{thread_rng, Rng};
388388
/// use rand::distributions::{Alphanumeric, Uniform, Standard};
389389
///
@@ -425,7 +425,7 @@ pub trait Rng: RngCore {
425425
///
426426
/// # Example
427427
///
428-
/// ```rust
428+
/// ```
429429
/// use rand::{thread_rng, Rng};
430430
///
431431
/// let mut arr = [0i8; 20];
@@ -454,7 +454,7 @@ pub trait Rng: RngCore {
454454
///
455455
/// # Example
456456
///
457-
/// ```rust
457+
/// ```
458458
/// # use rand::Error;
459459
/// use rand::{thread_rng, Rng};
460460
///
@@ -481,7 +481,7 @@ pub trait Rng: RngCore {
481481
///
482482
/// # Example
483483
///
484-
/// ```rust
484+
/// ```
485485
/// use rand::{thread_rng, Rng};
486486
///
487487
/// let mut rng = thread_rng();
@@ -546,7 +546,7 @@ pub trait Rng: RngCore {
546546
///
547547
/// # Example
548548
///
549-
/// ```rust
549+
/// ```
550550
/// use rand::{thread_rng, Rng};
551551
///
552552
/// let mut rng = thread_rng();
@@ -591,7 +591,7 @@ pub trait Rng: RngCore {
591591
///
592592
/// # Example
593593
///
594-
/// ```rust
594+
/// ```
595595
/// # #![allow(deprecated)]
596596
/// use rand::{thread_rng, Rng};
597597
///
@@ -614,7 +614,7 @@ pub trait Rng: RngCore {
614614
///
615615
/// # Example
616616
///
617-
/// ```rust
617+
/// ```
618618
/// # #![allow(deprecated)]
619619
/// use rand::{thread_rng, Rng};
620620
///
@@ -642,7 +642,7 @@ impl<R: RngCore + ?Sized> Rng for R {}
642642
/// PRNGs, though two alternatives may be considered:
643643
///
644644
/// * Deterministic creation using [`SeedableRng::from_seed`] with a fixed seed
645-
/// * Seeding from `thread_rng`: `SeedableRng::from_rng(thread_rng())?`;
645+
/// * Seeding from [`thread_rng`]: `SeedableRng::from_rng(thread_rng())?`;
646646
/// this will usually be faster and should also be secure, but requires
647647
/// trusting one extra component.
648648
///
@@ -655,9 +655,10 @@ impl<R: RngCore + ?Sized> Rng for R {}
655655
/// println!("Random die roll: {}", rng.gen_range(1, 7));
656656
/// ```
657657
///
658-
/// [`EntropyRng`]: struct.EntropyRng.html
658+
/// [`EntropyRng`]: rngs/struct.EntropyRng.html
659659
/// [`SeedableRng`]: trait.SeedableRng.html
660660
/// [`SeedableRng::from_seed`]: trait.SeedableRng.html#tymethod.from_seed
661+
/// [`thread_rng`]: fn.thread_rng.html
661662
#[cfg(feature="std")]
662663
pub trait FromEntropy: SeedableRng {
663664
/// Creates a new instance, automatically seeded with fresh entropy.
@@ -672,7 +673,7 @@ pub trait FromEntropy: SeedableRng {
672673
/// If all entropy sources fail this will panic. If you need to handle
673674
/// errors, use the following code, equivalent aside from error handling:
674675
///
675-
/// ```rust
676+
/// ```
676677
/// # use rand::Error;
677678
/// use rand::{Rng, StdRng, EntropyRng, SeedableRng};
678679
///
@@ -703,6 +704,9 @@ impl<R: SeedableRng> FromEntropy for R {
703704
/// documentation of the entropy source and [`Standard`] for documentation of
704705
/// distributions and type-specific generation.
705706
///
707+
/// Use [`thread_rng`] directly when you need more features, for example
708+
/// `thread_rng().gen_range(a, b)` to generate values uniformly in some range.
709+
///
706710
/// # Examples
707711
///
708712
/// ```

src/rngs/entropy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use {OsRng, JitterRng};
3030
/// external entropy then primarily use the local PRNG ([`thread_rng`] is
3131
/// provided as a convenient, local, automatically-seeded CSPRNG).
3232
///
33-
/// [`OsRng`]: os/struct.OsRng.html
34-
/// [`JitterRng`]: jitter/struct.JitterRng.html
35-
/// [`thread_rng`]: fn.thread_rng.html
33+
/// [`OsRng`]: struct.OsRng.html
34+
/// [`JitterRng`]: struct.JitterRng.html
35+
/// [`thread_rng`]: ../fn.thread_rng.html
3636
#[derive(Debug)]
3737
pub struct EntropyRng {
3838
rng: EntropySource,

src/rngs/read.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ use rand_core::{RngCore, Error, ErrorKind, impls};
2323
///
2424
/// `ReadRng` uses `std::io::read_exact`, which retries on interrupts. All other
2525
/// errors from the underlying reader, including when it does not have enough
26-
/// data, will only be reported through `try_fill_bytes`. The other `RngCore`
27-
/// methods will panic in case of an error error.
26+
/// data, will only be reported through [`try_fill_bytes`]. The other
27+
/// [`RngCore`] methods will panic in case of an error.
2828
///
2929
/// # Example
3030
///
31-
/// ```rust
31+
/// ```
3232
/// use rand::{read, Rng};
3333
///
3434
/// let data = vec![1, 2, 3, 4, 5, 6, 7, 8];
3535
/// let mut rng = read::ReadRng::new(&data[..]);
3636
/// println!("{:x}", rng.gen::<u32>());
3737
/// ```
38+
///
39+
/// [`RngCore`]: ../trait.RngCore.html
40+
/// [`try_fill_bytes`]: ../trait.RngCore.html#tymethod.try_fill_bytes
3841
#[derive(Debug)]
3942
pub struct ReadRng<R> {
4043
reader: R

src/rngs/small.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ use {RngCore, SeedableRng, Error};
1414
use prng::XorShiftRng;
1515

1616
/// An RNG recommended when small state, cheap initialization and good
17-
/// performance are required. The PRNG algorithm in `SmallRng` is chosen to be
18-
/// efficient on the current platform, **without consideration for cryptography
19-
/// or security**. The size of its state is much smaller than for [`StdRng`].
17+
/// performance are required.
18+
///
19+
/// The PRNG algorithm in `SmallRng` is chosen to be efficient on the current
20+
/// platform, **without consideration for cryptography or security**. The size
21+
/// of its state is much smaller than for [`StdRng`].
2022
///
2123
/// Reproducibility of output from this generator is however not required, thus
2224
/// future library versions may use a different internal generator with

0 commit comments

Comments
 (0)