Skip to content

Commit

Permalink
Merge pull request #1157 from rust-random/patch-1
Browse files Browse the repository at this point in the history
Better random chars example (take 2)
  • Loading branch information
vks committed Aug 17, 2021
2 parents 067238f + 1996707 commit 54e219d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
18 changes: 9 additions & 9 deletions Cargo.toml
Expand Up @@ -16,6 +16,15 @@ autobenches = true
edition = "2018"
include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"]

[package.metadata.docs.rs]
# To build locally:
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open
all-features = true
rustdoc-args = ["--cfg", "doc_cfg"]

[package.metadata.playground]
features = ["small_rng", "serde1"]

[features]
# Meta-features:
default = ["std", "std_rng"]
Expand Down Expand Up @@ -74,12 +83,3 @@ libc = { version = "0.2.22", optional = true, default-features = false }
rand_pcg = { path = "rand_pcg", version = "0.3.0" }
# Only to test serde1
bincode = "1.2.1"

[package.metadata.docs.rs]
# To build locally:
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open
all-features = true
rustdoc-args = ["--cfg", "doc_cfg"]

[package.metadata.playground]
features = ["small_rng", "serde1"]
18 changes: 9 additions & 9 deletions rand_core/Cargo.toml
Expand Up @@ -14,15 +14,6 @@ keywords = ["random", "rng"]
categories = ["algorithms", "no-std"]
edition = "2018"

[features]
std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug
alloc = [] # enables Vec and Box support without std
serde1 = ["serde"] # enables serde for BlockRng wrapper

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
getrandom = { version = "0.2", optional = true }

[package.metadata.docs.rs]
# To build locally:
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open
Expand All @@ -31,3 +22,12 @@ rustdoc-args = ["--cfg", "doc_cfg"]

[package.metadata.playground]
all-features = true

[features]
std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug
alloc = [] # enables Vec and Box support without std
serde1 = ["serde"] # enables serde for BlockRng wrapper

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
getrandom = { version = "0.2", optional = true }
15 changes: 9 additions & 6 deletions src/distributions/other.rs
Expand Up @@ -32,19 +32,22 @@ use std::mem::{self, MaybeUninit};
/// # Example
///
/// ```
/// use std::iter;
/// use rand::{Rng, thread_rng};
/// use rand::distributions::Alphanumeric;
///
/// let mut rng = thread_rng();
/// let chars: String = iter::repeat(())
/// .map(|()| rng.sample(Alphanumeric))
/// .map(char::from)
/// .take(7)
/// .collect();
/// let chars: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
/// println!("Random chars: {}", chars);
/// ```
///
/// The [`DistString`] trait provides an easier method of generating
/// a random `String`, and offers more efficient allocation:
/// ```
/// use rand::distributions::{Alphanumeric, DistString};
/// let string = Alphanumeric.sample_string(&mut rand::thread_rng(), 16);
/// println!("Random string: {}", string);
/// ```
///
/// # Passwords
///
/// Users sometimes ask whether it is safe to use a string of random characters
Expand Down

0 comments on commit 54e219d

Please sign in to comment.