NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #6 most downloaded on crates.io
Random number generators and other randomness functionality.
Last release 18 days ago
20 Sep 2026
Ships fairly regularly
a new release about every 2 months
Nearly every release is documented
notes for 58 of the last 60 stable releases
2 versions withdrawn
withdrawn after publishing
12 years old
94 releases · first in 2015
Fix WeightedIndex panic when the sum of float weights is infinite; return Error::Overflow instead
WeightedIndex panic when the sum of float weights is infinite; return Error::Overflow instead (#1808)Error::NonFinite from Uniform::new_inclusive on large finite float ranges such as 0.0..=f64::MAX (#1821)Uniform<char> (#1831)WeightedIndex::weights() and reduce overhead when reading weights (#1838)Full Changelog: 0.10.2...0.10.3
One column per quarter.
Fix possible memory safety violation due to deserialization of UniformChar from bad source
UniformChar from bad source (#1790)partial_shuffle and apply #[must_use] (#1769)unsafe in contexts where non-local memory corruption could invalidate contract (#1791)Full Changelog: 0.10.1...0.10.2
This release includes a fix for a soundness bug; see #1763 .
The dependency on rand_chacha has been replaced with a dependency on chacha20 . This changes the implementation behind StdRng , but the output remains
rand_chacha has been replaced with a dependency on chacha20. This changes the implementation behind StdRng, but the output remains the same. There may be some API breakage when using the ChaCha-types directly as these are now the ones in chacha20 instead of rand_chacha (#1642).IndexedRandom::choose_multiple -> sample, choose_multiple_array -> sample_array, choose_multiple_weighted -> sample_weighted, struct SliceChooseIter -> IndexedSamples and fns IteratorRandom::choose_multiple -> sample, choose_multiple_fill -> sample_fill (#1632)Fill be implemented for element types, not sliceable types (#1652)OsError::raw_os_error on UEFI targets by returning Option<usize> (#1665)TryRngCore::read_adapter(..) -> RngReadAdapter with simpler struct RngReader (#1669)SeedableRng::from_os_rng, try_from_os_rng (#1674)Clone support for StdRng, ReseedingRng (#1677)postcard instead of bincode to test the serde feature (#1693)IteratorRandom::sample when amount is much larger than iterator size (#1695)os_rng -> sys_rng, OsRng -> SysRng, OsError -> SysError (#1697)Rng -> RngExt as upstream rand_core has renamed RngCore -> Rng (#1717)IndexedRandom::choose_iter, choose_weighted_iter (#1632)Xoshiro128PlusPlus, Xoshiro256PlusPlus prngs (#1649)ChaCha8Rng, ChaCha12Rng, ChaCha20Rng behind chacha feature (#1659)rand::make_rng() -> R where R: SeedableRng (#1734)ReseedingRng (#1722)small_rng (#1732)Full Changelog: 0.9.2...0.10.0
rand_chacha has been replaced with a dependency on chacha20. This changes the implementation behind StdRng, but the output remains the same. There may be some API breakage when using the ChaCha-types directly as these are now the ones in chacha20 instead of rand_chacha (#1642).IndexedRandom::choose_multiple -> sample, choose_multiple_array -> sample_array, choose_multiple_weighted -> sample_weighted, struct SliceChooseIter -> IndexedSamples and fns IteratorRandom::choose_multiple -> sample, choose_multiple_fill -> sample_fill (#1632)Fill be implemented for element types, not sliceable types (#1652)OsError::raw_os_error on UEFI targets by returning Option<usize> (#1665)TryRngCore::read_adapter(..) -> RngReadAdapter with simpler struct RngReader (#1669)SeedableRng::from_os_rng, try_from_os_rng (#1674)Clone support for StdRng, ReseedingRng (#1677)postcard instead of bincode to test the serde feature (#1693)IteratorRandom::sample when amount is much larger than iterator size (#1695)os_rng -> sys_rng, OsRng -> SysRng, OsError -> SysError (#1697)Rng -> RngExt as upstream rand_core has renamed RngCore -> Rng (#1717)IndexedRandom::choose_iter, choose_weighted_iter (#1632)Xoshiro128PlusPlus, Xoshiro256PlusPlus prngs (#1649)ChaCha8Rng, ChaCha12Rng, ChaCha20Rng behind chacha feature (#1659)rand::make_rng() -> R where R: SeedableRng (#1734)@newpavlov this includes a number of what I think are uncontroversial changes from my other PRs and also bumps versions to allow publishing a new pre-
@newpavlov this includes a number of what I think are uncontroversial
changes from my other PRs and also bumps versions to allow publishing a
new pre-release.
I'm not committing to keeping rand_pcg in this repo but for now this is
the easiest approach (I also wouldn't make changes here until after
v0.10).
Rename Rng => RngExt ; bump rand_core to v0.10.0-rc-6
Rename Rng => RngExt; bump rand_core to v0.10.0-rc-6 (#1717)
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
rand v0.9.5: backport #1790 by @dhardy in #1803
Fixes Fix doc build ( #1766 ) Full Changelog : 0.9.3...0.9.4
This release back-ports a fix from v0.10. See also [ #1763 ].
Deprecate rand::mock module and StepRng generator ([#1634])
rand::rngs::mock module and StepRng generator ([#1634])WeightedIndex<usize> (de)serialization ([#1646])Revise "not a crypto library" policy again ([#1565])
simd_support for recent nightly rust (#1586)fn rand::seq::index::sample_weighted and fn IndexedRandom::choose_multiple_weighted to return fewer than amount results (#1623), reverting an undocumented change ([#1382]) to the previous release.Policy: "rand is not a crypto library" ([#1514])
ReseedingRng and ThreadRng. Instead, it is recommended to call ThreadRng::reseed on fork. (#1379)zerocopy to replace some unsafe code (#1349, #1393, #1446, #1502)--ignore-rust-versionrand_core v0.9.0 (#1558)std feature without getrandom or rand_chacha (#1354)small_rng by default (#1455)rand_chacha; use std_rng instead. (#1473)serde1 to serde (#1477)getrandom to os_rng (#1537)thread_rng (#1547)RngCore::read_adapter implementing std::io::Read (#1267)CryptoBlockRng: BlockRngCore; make trait CryptoRng: RngCore (#1273)TryRngCore, TryCryptoRng (#1424, #1499)fn SeedableRng::from_rng -> try_from_rng and add infallible variant fn from_rng (#1424)fn SeedableRng::from_entropy -> from_os_rng and add fallible variant fn try_from_os_rng (#1424)Clone and AsRef to associated type SeedableRng::Seed (#1491)rand::thread_rng() to rand::rng() and remove from the prelude (#1506)rand::random() from the prelude (#1506)random_iter, random_range, random_bool, random_ratio, fill (#1488)Rng::gen_iter as random_iter (#1305, #1500)Rng::gen to random to avoid conflict with the new gen keyword in Rust 2024 (#1438)Rng::gen_range to random_range, gen_bool to random_bool, gen_ratio to random_ratio (#1505)#[track_caller] (#1442, #1447)<SmallRng as SeedableRng>::Seed size to 256 bits (#1455)rng) of ReseedingRng::new (#1533)SliceRandom into IndexedRandom, IndexedMutRandom, SliceRandom (#1382)IndexedRandom::choose_multiple_array, index::sample_array (#1453, #1469)rand::distributions to rand::distr (#1470)Standard to StandardUniform (#1526)distr::Slice -> distr::slice::Choose, distr::EmptySlice -> distr::slice::Empty (#1548)distr::DistString -> distr::SampleString (#1548)distr::DistIter -> distr::Iter, distr::DistMap -> distr::Map (#1548)Sized bound on Distribution<T> for &D (#1278)Distribution<Option<T>> for StandardUniform (#1526)StandardUniform support all NonZero* types (#1332){Uniform, UniformSampler}::{new, new_inclusive} return a Result (instead of potentially panicking) (#1229)Uniform implements TryFrom instead of From for ranges (#1229)UniformUsize (#1487)isize and usize values with StandardUniform, Uniform (except via UniformUsize) and Fill and usage as a WeightedAliasIndex weight (#1487)DistString for distributions Slice<char> and Uniform<char> (#1315)Slice::num_choices (#1402)p() for distribution Bernoulli to access probability (#1481)pub module rand::distr::weighted, moving WeightedIndex there (#1548)weighted::Weight, allowing WeightedIndex to trap overflow (#1353)weight, weights, total_weight to distribution WeightedIndex (#1420)WeightedError to weighted::Error, revising variants (#1382) and mark as #[non_exhaustive] (#1480)std::simd, expand SIMD & docs (#1239)ReseedingRng::reseed discard remaining data from the last block generated (#1379)SmallRng::seed_from_u64 implementation (#1203)UniformFloat::new samples and UniformFloat::sample_single to yield high (#1462)Slice (#1469)Uniform for usize portable via UniformUsize (#1487)IndexdRandom::choose_multiple_weighted for very small seeds and optimize for large input length / low memory (#1530)sample_floyd, affecting output of rand::seq::index::sample and rand::seq::SliceRandom::choose_multiple (#1277)IteratorRandom::choose and choose_stable (#1268)SliceRandom::shuffle and partial_shuffle (#1272)Uniform: use Canon's method (single sampling) / Lemire's method (distribution sampling) for faster sampling (breaks value stability; #1287)sample_single_inclusive for floats (+~20% perf) (#1289)Cargo.lock.msrv file (#1275)rustfmt and enforce (#1448)benches crate (#1329, #1439) and migrate to Criterion (#1490)Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
v0.8: fix no-std + serde1 build by @dhardy in #1825
rand v0.8.7: backport #1790 by @dhardy in #1804
This release back-ports a fix from v0.10. See also #1763 .
This release back-ports a fix from v0.10. See also #1763.
log (#1772)simd_support feature.Full Changelog: 0.8.5...0.8.6
Fix build on non-32/64-bit architectures ([#1144])
no_std (#1173)libc::pthread_atfork return value with panic on error (#1178)ReseedingRng is used from a fork handler (#1178)slice_partition_at_index feature (#1215)simd_support: update packed_simd (#1216)StdRng: Switch from HC128 to ChaCha12 on emscripten (#1142).
We now use ChaCha12 on all platforms.Deprecate rngs::ReadRng ([#1130])
Clone and Copy for Alphanumeric ([#1126])Distribution::map to derive a distribution using a closure ([#1129])Slice distribution ([#1107])DistString trait with impls for Standard and Alphanumeric ([#1133])Uniform float distributions for easier debugging of non-finite arguments ([#1094], [#1108])Uniform float distributions ([#1108])rngs::adapter::ReadRng ([#1130])Fix no-std + alloc build by gating choose_multiple_weighted on std ([#1088])
no-std + alloc build by gating choose_multiple_weighted on std ([#1088])Fix panic in UniformInt::sample_single_inclusive and Rng::gen_range when providing a full integer range (eg 0..=MAX) ([#1087])
UniformInt::sample_single_inclusive and Rng::gen_range when providing a full integer range (eg 0..=MAX) ([#1087])Enable all stable features in the playground ([#1081])
The minimum supported Rust version is now 1.36 ([#1011])
getrandom updated to v0.2 (#1041)wasm-bindgen and stdweb feature flags. For details of WASM support, see the getrandom documentation. (#948)ReadRng::next_u32 and next_u64 now use little-Endian conversion instead of native-Endian, affecting results on Big-Endian platforms (#1061)nightly feature no longer implies the simd_support feature (#1048)simd_support feature to work on current nightlies (#1056)ThreadRng is no longer Copy to enable safe usage within thread-local destructors (#1035)gen_range(a, b) was replaced with gen_range(a..b). gen_range(a..=b) is also supported. Note that a and b can no longer be references or SIMD types. (#744, #1003)AsByteSliceMut with Fill and add support for [bool], [char], [f32], [f64] (#940)rand::rngs::adapter to std (#1027; see also [#928])StdRng: add new std_rng feature flag (enabled by default, but might need to be used if disabling default crate features) (#948)StdRng: Switch from ChaCha20 to ChaCha12 for better performance (#1028)SmallRng: Replace PCG algorithm with xoshiro{128,256}++ (#1038)IteratorRandom::choose_stable as an alternative to choose which does not depend on size hints (#1057)IteratorRandom::choose (#1059)IntoIterator for IndexVec, replacing the into_iter method (#1007)seq module (#933)PartialEq and Eq for StdRng, SmallRng and StepRng (#979)serde1 feature and added Serialize/Deserialize to UniformInt and WeightedIndex (#974)Alphanumeric samples bytes instead of chars (#935)Uniform now supports char, enabling rng.gen_range('A'..='Z') (#1068)UniformSampler::sample_single_inclusive (#1003)rand::distributions::alias_method::WeightedIndex was moved to rand_distr::WeightedAliasIndex. The simpler alternative rand::distribution::WeightedIndex remains. (#945)WeightedIndex::update_weights (#956)WeightedIndex: return error on NaN instead of panic (#1005)The Bernoulli distribution constructors now reports an error on NaN and on denominator == 0. ([#925])
Bernoulli distribution constructors now reports an error on NaN and on denominator == 0. ([#925])std::sync::Once to register fork handler, avoiding possible atomicity violation ([#928])std::error::Error for BernoulliError ([#919])Fix dependency on rand_core 0.5.1 ([#890])
rand_core 0.5.1 ([#890])This release was yanked since it depends on rand_core::OsRng added in 0.5.1 but specifies a dependency on version 0.5.0 ([#890]), causing broken build
This release was yanked since it depends on rand_core::OsRng added in 0.5.1 but specifies a dependency on version 0.5.0 ([#890]), causing broken builds when updating from rand 0.7.0 without also updating rand_core.
no_std behaviour, appropriately enable c2-chacha's std feature ([#844])alloc feature in no_std is available since Rust 1.36 ([#856])no_std target to CI to continuously evaluate no_std status ([#844])WeightedIndex: allow adjusting a sub-set of weights ([#866])Removed code already deprecated in version 0.6 ([#757])
Uniform for 8- and 16-bit ints (#809)rand_xorshift, rand_isaac, rand_jitter crates (#759, #765)winapi (#724)build.rs files (#824)rand_core 0.5.0Error type redesigned with new API (#800)from_entropy method to SeedableRng and remove FromEntropy (#800)SeedableRng::from_rng is now expected to be value-stable (#815)rand_os to new getrandom crate (#765, getrandom)StdRng and ThreadRng (#792)SmallRng (#792)ThreadRng now supports Copy (#758)EntropyRng (#765)ReseedingRng without std (#724)rand_distr (#761)Bernoulli::new constructor now returns a Result (#803)Distribution::sample_iter adjusted for more flexibility (#758)distributions::weighted::alias_method::WeightedIndex for O(1) sampling (#692)NonZeroU* types with the Standard distribution (#728)Binomial distribution sampling (#735, #740, #752)u32 samples for usize where possible (#809)Nothing published for this version
Nothing published for this version
Nothing published for this version
Update rand_core to 0.4 ([#703])
rand_core to 0.4 ([#703])JitterRng to its own crate ([#685])Move wasm-bindgen shims to correct crate ([#686])
wasm32-unknown-unknown compile but fail at run-time if missing bindings ([#686])Make the std feature require the optional rand_os dependency ([#675])
std feature require the optional rand_os dependency ([#675])rand_os from rand to avoid breakage ([#674])Add Default for ThreadRng ([#657])
Default for ThreadRng ([#657])rngs::OsRng to rand_os sub-crate; clean up code; use as dependency ([#643])rand_xoshiro sub-crate, plus benchmarks ([#642], [#668])UniformInt::sample_single ([#662])autocfg instead of rustc_version for rustc version detection ([#664])i128 and u128 if the target_os is emscripten ([#671]: work-around Emscripten limitation)UnitCircle and UnitSphereSurface distributions (no PR)Support sampling Duration also for no_std (only since Rust 1.25) ([#649])
Duration also for no_std (only since Rust 1.25) ([#649])libc ([#647])Remove functionality already deprecated in 0.5 ([#499])
OsRng for powerpc64, sparc and sparc64 (#609)syscall from libc on Linux instead of redefining it (#629)SmallRng to use PCG (#623)Pcg32 and Pcg64Mcg generators (#632)Rc from ThreadRng (#615)Rng.gen_ratio() and Bernoulli::new_ratio() (#491)Uniform strictly respect f32 / f64 high/low bounds (#477)gen_range and Uniform to work on non-Copy types (#506)Uniform supports inclusive ranges: Uniform::from(a..=b). This is automatically enabled for Rust >= 1.27. (#566)TrustedLen and FusedIterator for DistIter (#620)Dirichlet distribution (#485)Bernoulli::new (#500)char sampling (#519)std::time::Duration (#583)seq module (#483, #515)WeightedIndex and choose_weighted (#518, #547)sample_indices function (#479)Iterator::size_hint() to speed up IteratorRandom::choose (#593)i128 and u128 is automatically enabled for Rust >= 1.26. This renders the i128_support feature obsolete. It still exists for backwards compatibility but does not have any effect. This breaks programs using Rand with i128_support on nightlies older than Rust 1.26. (#571)Nothing published for this version
Nothing published for this version
Nothing published for this version
Fix links in documentation ([#582])
Make OsRng work via WASM/stdweb for WebWorkers
OsRng work via WASM/stdweb for WebWorkersOpenBSD, Bitrig: fix compilation (broken in 0.5.1) ([#530])
Hide OsRng and JitterRng on unsupported platforms ([#512]; fixes [#503])
OsRng and JitterRng on unsupported platforms ([#512]; fixes [#503])Added Cauchy distribution. ([#474], [#486])
OsRng/dev/random. ([#484])getentropy like OpenBSD. ([#484])getrandom if available, otherwise /dev/random. ([#484])stdweb: split the read up in chunks. ([#484])/dev/random. ([#484])fill_bytes. ([#484])Deprecate rand_derive. ([#256])
rand_core crate. (#288)rand_derive. (#256)prelude (and module reorganisation). (#435)log feature. Logging is now available in JitterRng, OsRng, EntropyRng and ReseedingRng. (#246)serde1 feature for some PRNGs. (#189)stdweb feature for OsRng support on WASM via stdweb. (#272, #336)Rng traitRng into RngCore and Rng extension trait. next_u32, next_u64 and fill_bytes are now part of RngCore. (#265)Rng::sample. (#256)Rng::gen_weighted_bool. (#308)Rng::gen_bool. (#308)Rng::next_f32 and Rng::next_f64. (#273)Rng::fill and Rng::try_fill methods. (#247)Rng::gen_iter. (#286)Rng::gen_ascii_chars. (#279)rand_core craterand now depends on new rand_core crate (#288)RngCore and SeedableRng are now part of rand_core. (#288)impl and le. (#209, #228)Error and ErrorKind. (#225)CryptoRng marker trait. (#273)BlockRngCore trait. (#281)BlockRng and BlockRng64 wrappers to help implementations. (#281, #325)SeedableRng trait. (#233)RngCore::next_u64 and RngCore::fill_bytes. (#288)RngCore::try_fill_bytes. (#225)FromEntropy trait. (#233, #375)SmallRng wrapper. (#296)ReseedingRng to only work with BlockRngCore (substantial performance improvement). (#281)weak_rng. Use SmallRng instead. (#296)AsciiGenerator. (#279)StdRng and thread_rng to HC-128. (#277)StdRng must now be created with from_entropy instead of newthread_rng reseeding threshold to 32 MiB. (#277)Copy. (#209)Debug implementations no longer show internals. (#209)Clone for ReseedingRng, JitterRng, OsRng`. (#383, #384)XorShiftRng, IsaacRng and Isaac64Rng under the serde1 feature. (#189)BlockRngCore for ChaChaCore and Hc128Core. (#281)Isaac64Rng::next_u32 no longer throws away half the results. (#209)IsaacRng::new_from_u64 and Isaac64Rng::new_from_u64. (#209)Hc128Rng. (#210)JitterRng to get its size down from 2112 to 24 bytes. (#251)OsRngOsRng via stdweb, behind the stdweb feature. (#272, #336)getrandom on more platforms for Linux, and on Android. (#338)SecRandomCopyBytes interface on macOS. (#322)OsRng. (#239)/dev/random, then /dev/urandom. (#338)OsRng (using new error type). (#225)OsRng now uses non-blocking when available. (#225)EntropyRng, which provides OsRng, but has JitterRng as a fallback. (#235)Distribution trait. (#256)Distribution::sample_iter and Rng::::sample_iter. (#361)Rand, Sample and IndependentSample traits. (#256)Standard distribution (replaces most Rand implementations). (#256)Binomial and Poisson distributions. (#96)Bernoulli dsitribution. (#411)Alphanumeric distribution. (#279)Closed01 distribution, add OpenClosed01. (#274, #420)Range type, making it possible to implement it for user types. (#274)Range to Uniform. (#395)Uniform::new_inclusive for inclusive ranges. (#274)Standard distribution for char uses Uniform internally. (#274)Standard distribution for bool uses sign test. (#274)Standard distribution for Wrapping<T>. (#436)Uniform distribution for Duration. (#427)Nothing published for this version
Nothing published for this version
Nothing published for this version
Fuchsia: Replaced fuchsia-zircon with fuchsia-cprng
Remove dependency on default features of rand_core ([#689])
rand_core ([#689])Version yanked due to semver-breaking change ([#688]).
Version yanked due to semver-breaking change ([#688]).
Your coding agent can read these notes before it upgrades. Set up the MCP server →