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
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
# Use no-std target to ensure we don't link to std.
run: cargo build --no-default-features --features alloc --target thumbv7m-none-eabi
- name: Test wasm
run: wasm-pack test --headless --chrome
run: RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-pack test --headless --chrome
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the fact that this flag is needed indicates that the getrandom upgrade needs to be considered a breaking change for our crate as well...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true, I'm afraid there's no way around that.

if: startsWith(matrix.os, 'ubuntu')
- run: cargo bench
if: startsWith(matrix.rust, 'nightly')
Expand All @@ -88,6 +88,11 @@ jobs:

msrv:
runs-on: ubuntu-latest
strategy:
matrix:
# When updating this, the reminder to update the minimum supported
# Rust version in Cargo.toml.
rust: ['1.63']
steps:
- uses: taiki-e/checkout-action@v1
- name: Install cargo-hack
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "fastrand"
version = "2.3.0"
authors = ["Stjepan Glavina <[email protected]>"]
edition = "2018"
rust-version = "1.36"
rust-version = "1.63"
description = "A simple and fast random number generator"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/smol-rs/fastrand"
Expand All @@ -21,16 +21,16 @@ std = ["alloc"]
js = ["std", "getrandom"]

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

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dev-dependencies]
wasm-bindgen-test = "0.3"
getrandom = { version = "0.2", features = ["js"] }
getrandom = { version = "0.3", features = ["wasm_js"] }

[dev-dependencies]
rand = "0.8"
wyhash = "0.5"
getrandom = "0.2"
rand = "0.9"
wyhash = "0.6"
getrandom = "0.3"

[package.metadata.docs.rs]
all-features = true
Expand Down
10 changes: 5 additions & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use wyhash::WyRng;

#[bench]
fn shuffle_wyhash(b: &mut Bencher) {
let mut rng = WyRng::from_rng(thread_rng()).unwrap();
let mut rng = WyRng::from_rng(&mut rand::rng());
let mut x = (0..100).collect::<Vec<usize>>();
b.iter(|| {
x.shuffle(&mut rng);
Expand All @@ -28,11 +28,11 @@ fn shuffle_fastrand(b: &mut Bencher) {

#[bench]
fn u8_wyhash(b: &mut Bencher) {
let mut rng = WyRng::from_rng(thread_rng()).unwrap();
let mut rng = WyRng::from_rng(&mut rand::rng());
b.iter(|| {
let mut sum = 0u8;
for _ in 0..10_000 {
sum = sum.wrapping_add(rng.gen::<u8>());
sum = sum.wrapping_add(rng.random::<u8>());
}
sum
})
Expand All @@ -52,11 +52,11 @@ fn u8_fastrand(b: &mut Bencher) {

#[bench]
fn u32_wyhash(b: &mut Bencher) {
let mut rng = WyRng::from_rng(thread_rng()).unwrap();
let mut rng = WyRng::from_rng(&mut rand::rng());
b.iter(|| {
let mut sum = 0u32;
for _ in 0..10_000 {
sum = sum.wrapping_add(rng.gen::<u32>());
sum = sum.wrapping_add(rng.random::<u32>());
}
sum
})
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ macro_rules! rng_integer {
};

let low = match range.start_bound() {
Bound::Unbounded => core::$t::MIN,
Bound::Unbounded => $t::MIN,
Bound::Included(&x) => x,
Bound::Excluded(&x) => x.checked_add(1).unwrap_or_else(panic_empty_range),
};

let high = match range.end_bound() {
Bound::Unbounded => core::$t::MAX,
Bound::Unbounded => $t::MAX,
Bound::Included(&x) => x,
Bound::Excluded(&x) => x.checked_sub(1).unwrap_or_else(panic_empty_range),
};
Expand All @@ -275,7 +275,7 @@ macro_rules! rng_integer {
panic_empty_range();
}

if low == core::$t::MIN && high == core::$t::MAX {
if low == $t::MIN && high == $t::MAX {
self.$gen() as $t
} else {
let len = high.wrapping_sub(low).wrapping_add(1);
Expand Down