All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
A separate changelog is kept for rand_core.
You may also find the Upgrade Guide useful.
- Add the
Slice::num_choices
method to the Slice distribution (#1402)
This is a pre-release. To depend on this version, use rand = "=0.9.0-alpha.0"
to prevent automatic updates (which can be expected to include breaking changes).
- Change
SmallRng::seed_from_u64
implementation (#1203) - Replace
SeedableRng
impl forSmallRng
with inherent methods, excludingfn from_seed
(#1368)
- Simpler and faster implementation of Floyd's F2 (#1277). This
changes some outputs from
rand::seq::index::sample
andrand::seq::SliceRandom::choose_multiple
. - New, faster algorithms for
IteratorRandom::choose
andchoose_stable
(#1268) - New, faster algorithms for
SliceRandom::shuffle
andpartial_shuffle
(#1272) - Re-introduce
Rng::gen_iter
(#1305) - Split trait
SliceRandom
intoIndexedRandom
,IndexedMutRandom
,SliceRandom
(#1382)
{Uniform, UniformSampler}::{new, new_inclusive}
return aResult
(instead of potentially panicking) (#1229)Uniform
implementsTryFrom
instead ofFrom
for ranges (#1229)Uniform
now uses Canon's method (single sampling) / Lemire's method (distribution sampling) for faster sampling (breaks value stability; #1287)- Relax
Sized
bound onDistribution<T> for &D
(#1278) - Explicit impl of
sample_single_inclusive
(+~20% perf) (#1289) - Impl
DistString
forSlice<char>
andUniform<char>
(#1315) - Let
Standard
support allNonZero*
types (#1332) - Add
trait Weight
, allowingWeightedIndex
to trap overflow (#1353) - Rename
WeightedError
toWeightError
, revising variants (#1382)
- Switch to
std::simd
, expand SIMD & docs (#1239) - Optimise SIMD widening multiply (#1247)
- Bump MSRV to 1.60.0 (#1207, #1246, #1269, #1341)
- Improve
thread_rng
related docs (#1257) - Add
Cargo.lock.msrv
file (#1275) - Docs: enable experimental
--generate-link-to-definition
feature (#1327) - Use
zerocopy
to replace someunsafe
code (#1349) - Support
std
feature withoutgetrandom
orrand_chacha
(#1354)
- Fix build on non-32/64-bit architectures (#1144)
- Fix "min_const_gen" feature for
no_std
(#1173) - Check
libc::pthread_atfork
return value with panic on error (#1178) - More robust reseeding in case
ReseedingRng
is used from a fork handler (#1178) - Fix nightly: remove unused
slice_partition_at_index
feature (#1215) - Fix nightly +
simd_support
: updatepacked_simd
(#1216)
StdRng
: Switch from HC128 to ChaCha12 on emscripten (#1142). We now use ChaCha12 on all platforms.
- Added docs about rand's use of const generics (#1150)
- Better random chars example (#1157)
- Use const-generics to support arrays of all sizes (#1104)
- Implement
Clone
andCopy
forAlphanumeric
(#1126) - Add
Distribution::map
to derive a distribution using a closure (#1129) - Add
Slice
distribution (#1107) - Add
DistString
trait with impls forStandard
andAlphanumeric
(#1133)
- Reorder asserts in
Uniform
float distributions for easier debugging of non-finite arguments (#1094, #1108) - Add range overflow check in
Uniform
float distributions (#1108) - Deprecate
rngs::adapter::ReadRng
(#1130)
- Fix
no-std
+alloc
build by gatingchoose_multiple_weighted
onstd
(#1088)
- Fix panic in
UniformInt::sample_single_inclusive
andRng::gen_range
when providing a full integer range (eg0..=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)- Remove
wasm-bindgen
andstdweb
feature flags. For details of WASM support, see the getrandom documentation. (#948) ReadRng::next_u32
andnext_u64
now use little-Endian conversion instead of native-Endian, affecting results on Big-Endian platforms (#1061)- The
nightly
feature no longer implies thesimd_support
feature (#1048) - Fix
simd_support
feature to work on current nightlies (#1056)
ThreadRng
is no longerCopy
to enable safe usage within thread-local destructors (#1035)gen_range(a, b)
was replaced withgen_range(a..b)
.gen_range(a..=b)
is also supported. Note thata
andb
can no longer be references or SIMD types. (#744, #1003)- Replace
AsByteSliceMut
withFill
and add support for[bool], [char], [f32], [f64]
(#940) - Restrict
rand::rngs::adapter
tostd
(#1027; see also #928) StdRng
: add newstd_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)
- Add
IteratorRandom::choose_stable
as an alternative tochoose
which does not depend on size hints (#1057) - Improve accuracy and performance of
IteratorRandom::choose
(#1059) - Implement
IntoIterator
forIndexVec
, replacing theinto_iter
method (#1007) - Add value stability tests for
seq
module (#933)
- Support
PartialEq
andEq
forStdRng
,SmallRng
andStepRng
(#979) - Added a
serde1
feature and added Serialize/Deserialize toUniformInt
andWeightedIndex
(#974) - Drop some unsafe code (#962, #963, #1011)
- Reduce packaged crate size (#983)
- Migrate to GitHub Actions from Travis+AppVeyor (#1073)
Alphanumeric
samples bytes instead of chars (#935)Uniform
now supportschar
, enablingrng.gen_range('A'..='Z')
(#1068)- Add
UniformSampler::sample_single_inclusive
(#1003)
- Implement weighted sampling without replacement (#976, #1013)
rand::distributions::alias_method::WeightedIndex
was moved torand_distr::WeightedAliasIndex
. The simpler alternativerand::distribution::WeightedIndex
remains. (#945)- Improve treatment of rounding errors in
WeightedIndex::update_weights
(#956) WeightedIndex
: return error on NaN instead of panic (#1005)
- Document types supported by
random
(#994) - Document notes on password generation (#995)
- Note that
SmallRng
may not be the best choice for performance and in some other cases (#1038) - Use
doc(cfg)
to annotate feature-gated items (#1019) - Adjust README (#1065)
- The
Bernoulli
distribution constructors now reports an error on NaN and ondenominator == 0
. (#925) - Use
std::sync::Once
to register fork handler, avoiding possible atomicity violation (#928) - Fix documentation on the precision of generated floating-point values
- Unix: make libc dependency optional; only use fork protection with std feature (#928)
- Implement
std::error::Error
forBernoulliError
(#919)
- Fix dependency on
rand_core
0.5.1 (#890)
- Unit tests for value stability of distributions added (#888)
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 a broken builds
when updating from rand 0.7.0
without also updating rand_core
.
- Fix
no_std
behaviour, appropriately enable c2-chacha'sstd
feature (#844) alloc
feature inno_std
is available since Rust 1.36 (#856)- Fix or squelch issues from Clippy lints (#840)
- Add a
no_std
target to CI to continuously evaluateno_std
status (#844) WeightedIndex
: allow adjusting a sub-set of weights (#866)
- Fix incorrect pointer usages revealed by Miri testing (#780, #781)
- Fix (tiny!) bias in
Uniform
for 8- and 16-bit ints (#809)
- Bumped MSRV (min supported Rust version) to 1.32.0
- Updated to Rust Edition 2018 (#823, #824)
- Removed dependence on
rand_xorshift
,rand_isaac
,rand_jitter
crates (#759, #765) - Remove dependency on
winapi
(#724) - Removed all
build.rs
files (#824) - Removed code already deprecated in version 0.6 (#757)
- Removed the serde1 feature (It's still available for backwards compatibility, but it does not do anything. #830)
- Many documentation changes
- Updated to
rand_core
0.5.0 Error
type redesigned with new API (#800)- Move
from_entropy
method toSeedableRng
and removeFromEntropy
(#800) SeedableRng::from_rng
is now expected to be value-stable (#815)
- OS interface moved from
rand_os
to newgetrandom
crate (#765, getrandom) - Use ChaCha for
StdRng
andThreadRng
(#792) - Feature-gate
SmallRng
(#792) ThreadRng
now supportsCopy
(#758)- Deprecated
EntropyRng
(#765) - Enable fork protection of ReseedingRng without
std
(#724)
- Many distributions have been moved to
rand_distr
(#761) Bernoulli::new
constructor now returns aResult
(#803)Distribution::sample_iter
adjusted for more flexibility (#758)- Added
distributions::weighted::alias_method::WeightedIndex
forO(1)
sampling (#692) - Support sampling
NonZeroU*
types with theStandard
distribution (#728) - Optimised
Binomial
distribution sampling (#735, #740, #752) - Optimised SIMD float sampling (#739)
- Make results portable across 32- and 64-bit by using
u32
samples forusize
where possible (#809)
- Update
rand_core
to 0.4 (#703) - Move
JitterRng
to its own crate (#685) - Add a wasm-bindgen test crate (#696)
- Fuchsia: Replaced fuchsia-zircon with fuchsia-cprng
- Use RFC 1946 for doc links (#691)
- Fix some doc links and notes (#711)
- Move wasm-bindgen shims to correct crate (#686)
- Make
wasm32-unknown-unknown
compile but fail at run-time if missing bindingsg (#686)
- Make the
std
feature require the optionalrand_os
dependency (#675) - Re-export the optional WASM dependencies of
rand_os
fromrand
to avoid breakage (#674)
- Add
Default
forThreadRng
(#657) - Move
rngs::OsRng
torand_os
sub-crate; clean up code; use as dependency (#643) ##BLOCKER## - Add
rand_xoshiro
sub-crate, plus benchmarks (#642, #668)
- Fix bias in
UniformInt::sample_single
(#662) - Use
autocfg
instead ofrustc_version
for rustc version detection (#664) - Disable
i128
andu128
if thetarget_os
isemscripten
(#671: work-around Emscripten limitation) - CI fixes (#660, #671)
- Optimise memory usage of
UnitCircle
andUnitSphereSurface
distributions (no PR)
- Support sampling
Duration
also forno_std
(only since Rust 1.25) (#649) - Disable default features of
libc
(#647)
- Rand has moved from rust-lang-nursery to rust-random! (#578)
- Created The Rust Random Book (source)
- Update copyright and licence notices (#591, #611)
- Migrate policy documentation from the wiki (#544)
- Add fork protection on Unix (#466)
- Added support for wasm-bindgen. (#541, #559, #562, #600)
- Enable
OsRng
for powerpc64, sparc and sparc64 (#609) - Use
syscall
fromlibc
on Linux instead of redefining it (#629)
- Switch
SmallRng
to use PCG (#623) - Implement
Pcg32
andPcg64Mcg
generators (#632) - Move ISAAC RNGs to a dedicated crate (#551)
- Move Xorshift RNG to its own crate (#557)
- Move ChaCha and HC128 RNGs to dedicated crates (#607, #636)
- Remove usage of
Rc
fromThreadRng
(#615)
- Implement
Rng.gen_ratio()
andBernoulli::new_ratio()
(#491) - Make
Uniform
strictly respectf32
/f64
high/low bounds (#477) - Allow
gen_range
andUniform
to work on non-Copy
types (#506) Uniform
supports inclusive ranges:Uniform::from(a..=b)
. This is automatically enabled for Rust >= 1.27. (#566)- Implement
TrustedLen
andFusedIterator
forDistIter
(#620)
- Add the
Dirichlet
distribution (#485) - Added sampling from the unit sphere and circle. (#567)
- Implement the triangular distribution (#575)
- Implement the Weibull distribution (#576)
- Implement the Beta distribution (#574)
- Optimise
Bernoulli::new
(#500) - Optimise
char
sampling (#519) - Optimise sampling of
std::time::Duration
(#583)
- Redesign the
seq
module (#483, #515) - Add
WeightedIndex
andchoose_weighted
(#518, #547) - Optimised and changed return type of the
sample_indices
function. (#479) - Use
Iterator::size_hint()
to speed upIteratorRandom::choose
(#593)
- Support for generating SIMD types (#523, #542, #561, #630)
- Revise CI scripts (#632, #635)
- Remove functionality already deprecated in 0.5 (#499)
- Support for
i128
andu128
is automatically enabled for Rust >= 1.26. This renders thei128_support
feature obsolete. It still exists for backwards compatibility but does not have any effect. This breaks programs using Rand withi128_support
on nightlies older than Rust 1.26. (#571)
- Fix links in documentation (#582)
- Make
OsRng
work via WASM/stdweb for WebWorkers
- OpenBSD, Bitrig: fix compilation (broken in 0.5.1) (#530)
- Hide
OsRng
andJitterRng
on unsupported platforms (#512; fixes #503).
- Added Cauchy distribution. (#474, #486)
- Added Pareto distribution. (#495)
- Remove blanket Unix implementation. (#484)
- Remove Wasm unimplemented stub. (#484)
- Dragonfly BSD: read from
/dev/random
. (#484) - Bitrig: use
getentropy
like OpenBSD. (#484) - Solaris: (untested) use
getrandom
if available, otherwise/dev/random
. (#484) - Emscripten,
stdweb
: split the read up in chunks. (#484) - Emscripten, Haiku: don't do an extra blocking read from
/dev/random
. (#484) - Linux, NetBSD, Solaris: read in blocking mode on first use in
fill_bytes
. (#484) - Fuchsia, CloudABI: fix compilation (broken in Rand 0.5). (#484)
- Minimum Rust version update: 1.22.0. (#239)
- Create a separate
rand_core
crate. (#288) - Deprecate
rand_derive
. (#256) - Add
prelude
(and module reorganisation). (#435) - Add
log
feature. Logging is now available inJitterRng
,OsRng
,EntropyRng
andReseedingRng
. (#246) - Add
serde1
feature for some PRNGs. (#189) stdweb
feature forOsRng
support on WASM via stdweb. (#272, #336)
- Split
Rng
inRngCore
andRng
extension trait.next_u32
,next_u64
andfill_bytes
are now part ofRngCore
. (#265) - Add
Rng::sample
. (#256) - Deprecate
Rng::gen_weighted_bool
. (#308) - Add
Rng::gen_bool
. (#308) - Remove
Rng::next_f32
andRng::next_f64
. (#273) - Add optimized
Rng::fill
andRng::try_fill
methods. (#247) - Deprecate
Rng::gen_iter
. (#286) - Deprecate
Rng::gen_ascii_chars
. (#279)
rand
now depends on newrand_core
crate (#288)RngCore
andSeedableRng
are now part ofrand_core
. (#288)- Add modules to help implementing RNGs
impl
andle
. (#209, #228) - Add
Error
andErrorKind
. (#225) - Add
CryptoRng
marker trait. (#273) - Add
BlockRngCore
trait. (#281) - Add
BlockRng
andBlockRng64
wrappers to help implementations. (#281, #325) - Revise the
SeedableRng
trait. (#233) - Remove default implementations for
RngCore::next_u64
andRngCore::fill_bytes
. (#288) - Add
RngCore::try_fill_bytes
. (#225)
- Add
FromEntropy
trait. (#233, #375) - Add
SmallRng
wrapper. (#296) - Rewrite
ReseedingRng
to only work withBlockRngCore
(substantial performance improvement). (#281) - Deprecate
weak_rng
. UseSmallRng
instead. (#296) - Deprecate
AsciiGenerator
. (#279)
- Switch
StdRng
andthread_rng
to HC-128. (#277) StdRng
must now be created withfrom_entropy
instead ofnew
- Change
thread_rng
reseeding threshold to 32 MiB. (#277) - PRNGs no longer implement
Copy
. (#209) Debug
implementations no longer show internals. (#209)- Implement
Clone
forReseedingRng
,JitterRng
, OsRng`. (#383, #384) - Implement serialization for
XorShiftRng
,IsaacRng
andIsaac64Rng
under theserde1
feature. (#189) - Implement
BlockRngCore
forChaChaCore
andHc128Core
. (#281) - All PRNGs are now portable across big- and little-endian architectures. (#209)
Isaac64Rng::next_u32
no longer throws away half the results. (#209)- Add
IsaacRng::new_from_u64
andIsaac64Rng::new_from_u64
. (#209) - Add the HC-128 CSPRNG
Hc128Rng
. (#210) - Change ChaCha20 to have 64-bit counter and 64-bit stream. (#349)
- Changes to
JitterRng
to get its size down from 2112 to 24 bytes. (#251) - Various performance improvements to all PRNGs.
- Add support for CloudABI. (#224)
- Remove support for NaCl. (#225)
- WASM support for
OsRng
via stdweb, behind thestdweb
feature. (#272, #336) - Use
getrandom
on more platforms for Linux, and on Android. (#338) - Use the
SecRandomCopyBytes
interface on macOS. (#322) - On systems that do not have a syscall interface, only keep a single file descriptor open for
OsRng
. (#239) - On Unix, first try a single read from
/dev/random
, then/dev/urandom
. (#338) - Better error handling and reporting in
OsRng
(using new error type). (#225) OsRng
now uses non-blocking when available. (#225)- Add
EntropyRng
, which providesOsRng
, but hasJitterRng
as a fallback. (#235)
- New
Distribution
trait. (#256) - Add
Distribution::sample_iter
andRng::::sample_iter
. (#361) - Deprecate
Rand
,Sample
andIndependentSample
traits. (#256) - Add a
Standard
distribution (replaces mostRand
implementations). (#256) - Add
Binomial
andPoisson
distributions. (#96) - Add
Bernoulli
dsitribution. (#411) - Add
Alphanumeric
distribution. (#279) - Remove
Closed01
distribution, addOpenClosed01
. (#274, #420) - Rework
Range
type, making it possible to implement it for user types. (#274) - Rename
Range
toUniform
. (#395) - Add
Uniform::new_inclusive
for inclusive ranges. (#274) - Use widening multiply method for much faster integer range reduction. (#274)
Standard
distribution forchar
usesUniform
internally. (#274)Standard
distribution forbool
uses sign test. (#274)- Implement
Standard
distribution forWrapping<T>
. (#436) - Implement
Uniform
distribution forDuration
. (#427)
- Use correct syscall number for PowerPC (#589)
- Use
winapi
on Windows - Update for Fuchsia OS
- Remove dev-dependency on
log
no_std
support
JitterRng
added as a high-quality alternative entropy source using the system timer- new
seq
module withsample_iter
,sample_slice
, etc. - WASM support via dummy implementations (fail at run-time)
- Additional benchmarks, covering generators and new seq code
thread_rng
usesJitterRng
if seeding from system time fails (slower but more secure than previous method)
sample
function deprecated (replaced bysample_iter
)
- Remove dev-dependency on
log
- Update
fuchsia-zircon
dependency to 0.3.2
- Require
log <= 0.3.8
for dev builds - Update
fuchsia-zircon
dependency to 0.3 - Fix broken links in docs (to unblock compiler docs testing CI)
thread_rng
is seeded from the system time ifOsRng
failsweak_rng
now usesthread_rng
internally
- Fuchsia: Magenta was renamed Zircon
- Implement Debug for mote non-public types
- implement
Rand
for (i|u)i128 - Support for Fuchsia
- Add inline attribute to SampleRange::construct_range. This improves the benchmark for sample in 11% and for shuffle in 16%.
- Use
RtlGenRandom
instead ofCryptGenRandom
- Add
Rng
trait methodchoose_mut
- Redox support
- Use
arc4rand
forOsRng
on FreeBSD. - Use
arc4random(3)
forOsRng
on OpenBSD.
- Fix filling buffers 4 GiB or larger with
OsRng::fill_bytes
on Windows
- Inline definitions from winapi/advapi32, which decreases build times
- Compatible with Rust 1.7.0-nightly (needed some extra type annotations)
- Replaced the methods in
next_f32
andnext_f64
with the technique described Saito & Matsumoto at MCQMC'08. The new method should exhibit a slightly more uniform distribution. - Depend on libc 0.2
- Fix iterator protocol issue in
rand::sample
- Implement
Rand
for arrays with n <= 32
- Support for NaCl platforms
- Allow
Rng
to be?Sized
, impl for&mut R
andBox<R>
whereR: ?Sized + Rng
- Use
winapi
for Windows API things
- Fixed test on stable/nightly
- Fix
getrandom
syscall number for aarch64-unknown-linux-gnu
log
is a dev dependency
- Fix race condition of atomics in
is_getrandom_available
- Derive Copy/Clone changes
- Move to stable Rust!
- Compatible with Rust master
- Implement Clone for
Weighted
- Compatible with Rust master
- Fix compile on Windows
- Fix compile on Windows
- Update to use log version 0.3.x
- Compatible with Rust master
- Fixed iOS compilation
- Compatible with Rust master (move from
old_io
tostd::io
)
- Compatible with Rust master (use wrapping ops)
- Compatible with Rust master
- Removed Copy implementations from RNGs
- Imported functionality from
std::rand
, including:StdRng
,SeedableRng
,TreadRng
,weak_rng()
ReaderRng
: A wrapper around any Reader to treat it as an RNG.
- Imported documentation from
std::rand
- Imported tests from
std::rand
- Migrate to a cargo-compatible directory structure.
- Do not use entropy during
gen_weighted_bool(1)
- Impl Rand for tuples of arity 11 and 12
- Include ChaCha pseudorandom generator
- Add
next_f64
andnext_f32
to Rng - Implement Clone for PRNGs
- Rename
TaskRng
toThreadRng
andtask_rng
tothread_rng
(since a runtime is removed from Rust).
- Improved performance of ISAAC and ISAAC64 by 30% and 12 % respectively, by informing the optimiser that indexing is never out-of-bounds.
- Removed the Deprecated
choose_option
- document when to use
OSRng
in cryptographic context, and explain why we use/dev/urandom
instead of/dev/random
Rng::gen_iter()
which will return an infinite stream of random valuesRng::gen_ascii_chars()
which will return an infinite stream of random ascii characters
- Now only depends on libcore!
- Remove
Rng.choose()
, renameRng.choose_option()
to.choose()
- Rename OSRng to OsRng
- The WeightedChoice structure is no longer built with a
Vec<Weighted<T>>
, but rather a&mut [Weighted<T>]
. This means that the WeightedChoice structure now has a lifetime associated with it. - The
sample
method onRng
has been moved to a top-level function in therand
module due to its dependence onVec
.
Rng::gen_vec()
was removed. Previous behavior can be regained withrng.gen_iter().take(n).collect()
Rng::gen_ascii_str()
was removed. Previous behavior can be regained withrng.gen_ascii_chars().take(n).collect()
- {IsaacRng, Isaac64Rng, XorShiftRng}::new() have all been removed. These all
relied on being able to use an OSRng for seeding, but this is no longer
available in librand (where these types are defined). To retain the same
functionality, these types now implement the
Rand
trait so they can be generated with a random seed from another random number generator. This allows the stdlib to use an OSRng to create seeded instances of these RNGs. - Rand implementations for
Box<T>
and@T
were removed. These seemed to be pretty rare in the codebase, and it allows for librand to not depend on liballoc. Additionally, other pointer types like Rc and Arc were not supported. - Remove a slew of old deprecated functions
- replace
Rng.shuffle's
functionality with.shuffle_mut
- bubble up IO errors when creating an OSRng
- Use
fill()
instead ofread()
- Rewrite OsRng in Rust for windows
- Separate
rand
out of the standard library