Skip to content

Commit

Permalink
Add example for using rand (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
vks committed Dec 14, 2023
1 parent 1cc3f88 commit 14d036c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions rand_pcg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rand_core = { path = "../rand_core", version = "0.7.0" }
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
rand = { path = "..", version = "0.9" }
# This is for testing serde, unfortunately we can't specify feature-gated dev
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
# Versions prior to 1.1.4 had incorrect minimal dependencies.
Expand Down
14 changes: 12 additions & 2 deletions rand_pcg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@
//!
//! To initialize a generator, use the [`SeedableRng`][rand_core::SeedableRng] trait:
//!
//! ```rust
//! ```
//! use rand_core::{SeedableRng, RngCore};
//! use rand_pcg::Pcg64Mcg;
//!
//! let mut rng = Pcg64Mcg::seed_from_u64(0);
//! // Alternatively, you may use `Pcg64Mcg::from_entropy()`.
//! let x: u32 = rng.next_u32();
//! ```
//!
//! The functionality of this crate is implemented using traits from the `rand_core` crate, but you may use the `rand`
//! crate for further functionality to initialize the generator from various sources and to generate random values:
//!
//! ```
//! use rand::{Rng, SeedableRng};
//! use rand_pcg::Pcg64Mcg;
//!
//! let mut rng = Pcg64Mcg::from_entropy();
//! let x: f64 = rng.gen();
//! ```

#![doc(
html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
Expand Down

0 comments on commit 14d036c

Please sign in to comment.