Skip to content

Commit

Permalink
Clarify documentation for fork() (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull authored Jun 15, 2023
1 parent 6315dd1 commit 96c01d9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,25 @@ impl Rng {
/// Clones the generator by deterministically deriving a new generator based on the initial
/// seed.
///
/// This function can be used to create a new generator that is a "spinoff" of the old
/// generator. The new generator will not produce the same sequence of values as the
/// old generator.
///
/// # Example
///
/// ```
/// // Seed two generators equally, and clone both of them.
/// let mut base1 = fastrand::Rng::new();
/// base1.seed(0x4d595df4d0f33173);
/// let mut base1 = fastrand::Rng::with_seed(0x4d595df4d0f33173);
/// base1.bool(); // Use the generator once.
///
/// let mut base2 = fastrand::Rng::new();
/// base2.seed(0x4d595df4d0f33173);
/// let mut base2 = fastrand::Rng::with_seed(0x4d595df4d0f33173);
/// base2.bool(); // Use the generator once.
///
/// let mut rng1 = base1.clone();
/// let mut rng2 = base2.clone();
/// let mut rng1 = base1.fork();
/// let mut rng2 = base2.fork();
///
/// assert_eq!(rng1.u64(..), rng2.u64(..), "the cloned generators are identical");
/// println!("rng1 returns {}", rng1.u32(..));
/// println!("rng2 returns {}", rng2.u32(..));
/// ```
#[inline]
#[must_use = "this creates a new instance of `Rng`"]
Expand Down

0 comments on commit 96c01d9

Please sign in to comment.