Skip to content

Commit

Permalink
Re-write the in-doc quick-start
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Sep 24, 2024
1 parent 2de9c93 commit a785c60
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@
//!
//! # Quick Start
//!
//! To get you started quickly, the easiest and highest-level way to get
//! a random value is to use [`random()`]; alternatively you can use
//! [`thread_rng()`]. The [`Rng`] trait provides a useful API on all RNGs, while
//! the [`distr`] and [`seq`] modules provide further
//! functionality on top of RNGs.
//!
//! ```
//! use rand::prelude::*;
//! // Get an RNG:
//! let mut rng = rand::thread_rng();
//!
//! if rand::random() { // generates a boolean
//! // Try printing a random unicode code point (probably a bad idea)!
//! println!("char: {}", rand::random::<char>());
//! }
//! // Try printing a random unicode code point (probably a bad idea)!
//! println!("char: '{}'", rng.random::<char>());
//! // Try printing a random alphanumeric value instead!
//! println!("alpha: '{}'", rng.sample(rand::distr::Alphanumeric) as char);
//!
//! let mut rng = rand::thread_rng();
//! let y: f64 = rng.random(); // generates a float between 0 and 1
//! // The prelude makes choose and shuffle available on sequences:
//! use rand::prelude::*;
//!
//! // Generate and shuffle a sequence:
//! let mut nums: Vec<i32> = (1..100).collect();
//! nums.shuffle(&mut rng);
//! // And take a random pick (yes, we didn't need to shuffle first!):
//! let _ = nums.choose(&mut rng);
//! ```
//!
//! # The Book
Expand Down

0 comments on commit a785c60

Please sign in to comment.