Skip to content

Commit

Permalink
Merge pull request #4 from rust-random/make_seed
Browse files Browse the repository at this point in the history
Add Seeder::make_seed
  • Loading branch information
dhardy authored May 22, 2020
2 parents 9696d5e + 5502d0f commit 3d31fa2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.1] - 2020-05-22
Add `Seeder::make_seed`.

## [0.2.0] - 2019-11-04
Documentation reviewed and improved.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_seeder"
version = "0.2.0" # NB: When modifying, also modify html_root_url in lib.rs
version = "0.2.1" # NB: When modifying, also modify html_root_url in lib.rs
authors = ["The Rand Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
html_root_url = "https://docs.rs/rand_seeder/0.2.0")]
html_root_url = "https://docs.rs/rand_seeder/0.2.1")]

#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
Expand Down Expand Up @@ -89,10 +89,20 @@ impl Seeder {
///
/// Alternatively, one can obtain a [`SipRng`] via
/// `SipHasher::from(h).into_rng()`.
#[inline]
pub fn make_rng<R: SeedableRng>(&mut self) -> R {
let mut seed = R::Seed::default();
R::from_seed(self.make_seed())
}

/// Make a seed
///
/// This mutates the state internally, thus can be called multiple times to
/// generate multiple independent seeds.
#[inline]
pub fn make_seed<S: AsMut<[u8]> + Default>(&mut self) -> S {
let mut seed = S::default();
self.rng.fill_bytes(seed.as_mut());
R::from_seed(seed)
seed
}
}

Expand Down

0 comments on commit 3d31fa2

Please sign in to comment.