Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
variant: MSRV
toolchain: 1.63.0
toolchain: 1.85.0
- os: ubuntu-latest
deps: sudo apt-get update ; sudo apt install gcc-multilib
target: i686-unknown-linux-gnu
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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).

## [Unreleased]
## [0.5.0] - 2026-02-02

- Rename `Seeder::make_rng` → `Seeder::into_rng`
- Bump MSRV to 1.85.0 (#22)
- Update to `rand_core` v0.10 (#22)

## [0.4.0] - 2025-01-27

- Update to `rand_core` v0.9
- Rename `Seeder::make_rng` → `Seeder::into_rng` (#11)

## [0.3.0] - 2024-07-31

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_seeder"
version = "0.4.0" # NB: When modifying, also modify html_root_url in lib.rs
version = "0.5.0" # 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 All @@ -12,11 +12,11 @@ A universal random number seeder based on SipHash.
"""
keywords = ["random", "rng", "seeder"]
categories = ["algorithms", "no-std"]
edition = "2021"
rust-version = "1.63"
edition = "2024"
rust-version = "1.85.0"

[dependencies]
rand_core = { version = "0.9.0", default-features = false }
rand_core = { version = "0.10.0", default-features = false }

[lints.clippy]
unit_arg = "allow"
Expand Down
4 changes: 2 additions & 2 deletions benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const RAND_BENCH_N: u64 = 1000;
const BYTES_LEN: usize = 1024;

use std::mem::size_of;
use test::{black_box, Bencher};
use test::{Bencher, black_box};

use rand_seeder::rand_core::RngCore;
use rand_seeder::rand_core::Rng;
use rand_seeder::{Seeder, SipRng};

#[bench]
Expand Down
2 changes: 1 addition & 1 deletion examples/seedrng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

extern crate rand_seeder;

use rand_seeder::rand_core::RngCore;
use rand_seeder::SipHasher;
use rand_seeder::rand_core::Rng;

use std::env;
use std::hash::Hasher;
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! # Example
//!
//! ```
//! use rand_seeder::rand_core::RngCore;
//! use rand_seeder::rand_core::Rng;
//! use rand_seeder::SipRng; // or any RNG supporting SeedableRng
//! use rand_seeder::Seeder;
//!
Expand All @@ -38,7 +38,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.4.0"
html_root_url = "https://docs.rs/rand_seeder/0.5.0"
)]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
Expand All @@ -52,7 +52,7 @@ mod sip;
pub use sip::{SipHasher, SipRng};

use core::hash::Hash;
use rand_core::{RngCore, SeedableRng};
use rand_core::{Rng, SeedableRng};

/// A simple interface for universal seeding
///
Expand All @@ -69,7 +69,7 @@ use rand_core::{RngCore, SeedableRng};
/// ```rust
/// # extern crate rand_core;
/// # extern crate rand_seeder;
/// use rand_core::RngCore;
/// use rand_core::Rng;
/// use rand_seeder::{Seeder, SipRng};
///
/// // Use any R: SeedableRng you like in place of SipRng:
Expand Down
25 changes: 12 additions & 13 deletions src/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use core::marker::PhantomData;
use core::{cmp, hash, mem, ptr, slice};
use rand_core::{impls, le, RngCore, SeedableRng};
use rand_core::{Infallible, Rng, SeedableRng, TryRng, utils};

/// A portable implementation of SipHash 2-4.
///
Expand Down Expand Up @@ -82,9 +82,7 @@ struct State {
}

macro_rules! compress {
($state:expr) => {{
compress!($state.v0, $state.v1, $state.v2, $state.v3)
}};
($state:expr) => {{ compress!($state.v0, $state.v1, $state.v2, $state.v3) }};
($v0:expr, $v1:expr, $v2:expr, $v3:expr) => {{
$v0 = $v0.wrapping_add($v1);
$v1 = $v1.rotate_left(13);
Expand Down Expand Up @@ -181,32 +179,33 @@ impl SipRng {
}
}

impl RngCore for SipRng {
fn next_u32(&mut self) -> u32 {
impl TryRng for SipRng {
type Error = Infallible;

fn try_next_u32(&mut self) -> Result<u32, Infallible> {
// Lazy way to implement. Good enough for seeding RNGs.
self.next_u64() as u32
Ok(self.next_u64() as u32)
}

fn next_u64(&mut self) -> u64 {
fn try_next_u64(&mut self) -> Result<u64, Infallible> {
self.state.v2 ^= self.adj;
self.adj = self.adj.wrapping_sub(0x11);

Sip24Rounds::c_rounds(&mut self.state);

self.state.v0 ^ self.state.v1 ^ self.state.v2 ^ self.state.v3
Ok(self.state.v0 ^ self.state.v1 ^ self.state.v2 ^ self.state.v3)
}

fn fill_bytes(&mut self, dest: &mut [u8]) {
impls::fill_bytes_via_next(self, dest)
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Infallible> {
utils::fill_bytes_via_next_word(dest, || self.try_next_u64())
}
}

impl SeedableRng for SipRng {
type Seed = [u8; 32];

fn from_seed(seed: Self::Seed) -> Self {
let mut keys = [0u64; 4];
le::read_u64_into(&seed, &mut keys);
let keys: [u64; 4] = utils::read_words(&seed);
SipRng::from_state(State {
v0: keys[0],
v1: keys[1],
Expand Down