Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ alloc = []
std = ["alloc"]
js = ["std", "getrandom"]

[dependencies.rapidhash]
version = "4"
default-features = false

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"], optional = true }

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ https://docs.rs/fastrand)

A simple and fast random number generator.

The implementation uses [Wyrand](https://github.com/wangyi-fudan/wyhash), a simple and fast
The implementation uses [rapidhash](https://github.com/hoxxep/rapidhash), a simple and fast
generator but **not** cryptographically secure.

## Examples
Expand Down
12 changes: 2 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A simple and fast random number generator.
//!
//! The implementation uses [Wyrand](https://github.com/wangyi-fudan/wyhash), a simple and fast
//! The implementation uses [rapidhash](https://github.com/hoxxep/rapidhash), a simple and fast
//! generator but **not** cryptographically secure.
//!
//! # Examples
Expand Down Expand Up @@ -147,15 +147,7 @@ impl Rng {
/// Generates a random `u64`.
#[inline]
fn gen_u64(&mut self) -> u64 {
// Constants for WyRand taken from: https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h#L151
// Updated for the final v4.2 implementation with improved constants for better entropy output.
const WY_CONST_0: u64 = 0x2d35_8dcc_aa6c_78a5;
const WY_CONST_1: u64 = 0x8bb8_4b93_962e_acc9;

let s = self.0.wrapping_add(WY_CONST_0);
self.0 = s;
let t = u128::from(s) * u128::from(s ^ WY_CONST_1);
(t as u64) ^ (t >> 64) as u64
rapidhash::rng::rapidrng_fast_not_portable(&mut self.0)
}

/// Generates a random `u128`.
Expand Down
Loading