Skip to content

Upgrading rand 0.8 to 0.9

Breaking0.8.8 → 0.9.5Breaking39Security7Platform5Deprecated2New59Changed37Fixed23Other71

BreakingUpgrade verdict

36 breaking changes and 5 platform requirement changes and 7 security fixes.

  • Rename fn SeedableRng::from_rng -> try_from_rng and add infallible variant fn from_rng.
  • Rename fn SeedableRng::from_entropy -> from_os_rng and add fallible variant fn try_from_os_rng.
  • Rename fn rand::thread_rng() to rand::rng() and remove from the prelude.
  • Remove fn rand::random() from the prelude.
Top 5 of 50 that need code or config changes

Requires Rust 1.63 from 0.9.0-beta.0 (none stated before).

Adds rayon ^1.7.

Drops libc.

Installs 23 packages in all (was 18).

Breaking36
Rename fn SeedableRng::from_rng -> try_from_rng and add infallible variant fn from_rng.
try_from_rng
Rename fn SeedableRng::from_entropy -> from_os_rng and add fallible variant fn try_from_os_rng.
from_os_rng
Rename fn rand::thread_rng() to rand::rng() and remove from the prelude.
rand::thread_rng()rand::rng()
Remove fn rand::random() from the prelude.
rand::random()
Rename fn Rng::gen to random to avoid conflict with the new gen keyword in Rust 2024.
Rng::genrandomgen
Rename fns Rng::gen_range to random_range, gen_bool to random_bool, gen_ratio to random_ratio.
Rng::gen_rangerandom_rangegen_boolrandom_boolgen_ratiorandom_ratio
Remove first parameter (rng) of ReseedingRng::new.
rngReseedingRng::new
Rename module rand::distributions to rand::distr.
rand::distributionsrand::distr
Rename distribution Standard to StandardUniform.
StandardStandardUniform
Rename trait distr::DistString -> distr::SampleString.
distr::DistStringdistr::SampleString
Rename distr::DistIter -> distr::Iter, distr::DistMap -> distr::Map.
distr::DistIterdistr::Iterdistr::DistMapdistr::Map
Remove impl of Distribution<Option> for StandardUniform.
Distribution<Option<T>>StandardUniform
Remove support for generating isize and usize values with StandardUniform, Uniform (except via UniformUsize) and Fill and usage as a WeightedAliasIndex weight.
isizeusizeStandardUniformUniformUniformUsizeFill
Rename enum WeightedError to weighted::Error, revising variants and mark as #[non_exhaustive].
WeightedErrorweighted::Error#[non_exhaustive]
Remove unused fields.
Remove redundant bounds.
Rename WeightedError → WeightError; add IndexedRandom, IndexedMutRandom.
Remove automatic (delayed) reseed-on-fork.
Rename Rng::gen to Rng::random.
Rng::genRng::random
Rename doc_cfg to docsrs and use doc_auto_cfg.
doc_cfgdocsrsdoc_auto_cfg
Rename serde1 feature to serde.
serde1serde
Rename gen_iter → random_iter, misc.
Remove some unsafe, update to zerocopy 0.8.0.
Remove u64 support for Poisson.
Remove conditional compilation around using core.
Remove SmallRng::from_thread_rng.
Make ReseedingRng::reseed discard remaining data from the last block generated.
ReseedingRng::reseed
Change fn SmallRng::seed_from_u64 implementation.
SmallRng::seed_from_u64
Allow UniformFloat::new samples and UniformFloat::sample_single to yield high.
UniformFloat::newUniformFloat::sample_singlehigh
Fix portability of distribution Slice.
Slice
Fix IndexdRandom::choose_multiple_weighted for very small seeds and optimize for large input length / low memory.
IndexdRandom::choose_multiple_weighted
Optimize fn sample_floyd, affecting output of rand::seq::index::sample and rand::seq::SliceRandom::choose_multiple.
sample_floydrand::seq::index::samplerand::seq::SliceRandom::choose_multiple
New, faster algorithms for IteratorRandom::choose and choose_stable.
IteratorRandom::choosechoose_stable
New, faster algorithms for SliceRandom::shuffle and partial_shuffle.
SliceRandom::shufflepartial_shuffle
Optimize distribution Uniform: use Canon's method (single sampling) / Lemire's method (distribution sampling) for faster sampling (breaks value stability; ).
Uniform
Optimize fn sample_single_inclusive for floats (+~20% perf).
sample_single_inclusive
Security7
Rand is unsound with a custom logger using rand::rng()
Revise "not a crypto library" policy again.
Remove zerocopy dependency from rand.
zerocopyrand
Policy: "rand is not a crypto library".
Remove fork-protection from ReseedingRng and ThreadRng.
ReseedingRngThreadRngThreadRng::reseed
Use zerocopy to replace some unsafe code.
zerocopyunsafe
GitHub Workflows security hardening.
Platform5
Bump the MSRV to 1.63.0; note that 1.60.0 may work for dependents when using --ignore-rust-version.
--ignore-rust-version
Bump MSRV to 1.51.0.
Bump MSRV to 1.56 (Edition 2021).
Bump the MSRV to 1.61.0.
Bump the MSRV to 1.63.0.
Deprecated2
Deprecate feature log.
log
Deprecate rand::rngs::mock module and StepRng generator.
rand::rngs::mockStepRng