Upgrade guide
See https://rust-random.github.io/book/update-0.9.html
Changelog
Security and unsafe
- Policy: "rand is not a crypto library" (#1514)
- Remove fork-protection from
ReseedingRng
andThreadRng
. Instead, it is recommended to callThreadRng::reseed
on fork. (#1379) - Use
zerocopy
to replace someunsafe
code (#1349, #1393, #1446, #1502)
Dependencies
- Bump the MSRV to 1.63.0 (#1207, #1246, #1269, #1341, #1416, #1536); note that 1.60.0 may work for dependents when using
--ignore-rust-version
- Update to
rand_core
v0.9.0 (#1558)
Features
- Support
std
feature withoutgetrandom
orrand_chacha
(#1354) - Enable feature
small_rng
by default (#1455) - Remove implicit feature
rand_chacha
; usestd_rng
instead. (#1473) - Rename feature
serde1
toserde
(#1477) - Rename feature
getrandom
toos_rng
(#1537) - Add feature
thread_rng
(#1547)
API changes: rand_core traits
- Add fn
RngCore::read_adapter
implementingstd::io::Read
(#1267) - Add trait
CryptoBlockRng: BlockRngCore
; maketrait CryptoRng: RngCore
(#1273) - Add traits
TryRngCore
,TryCryptoRng
(#1424, #1499) - Rename
fn SeedableRng::from_rng
->try_from_rng
and add infallible variantfn from_rng
(#1424) - Rename
fn SeedableRng::from_entropy
->from_os_rng
and add fallible variantfn try_from_os_rng
(#1424) - Add bounds
Clone
andAsRef
to associated typeSeedableRng::Seed
(#1491)
API changes: Rng trait and top-level fns
- Rename fn
rand::thread_rng()
torand::rng()
and remove from the prelude (#1506) - Remove fn
rand::random()
from the prelude (#1506) - Add top-level fns
random_iter
,random_range
,random_bool
,random_ratio
,fill
(#1488) - Re-introduce fn
Rng::gen_iter
asrandom_iter
(#1305, #1500) - Rename fn
Rng::gen
torandom
to avoid conflict with the newgen
keyword in Rust 2024 (#1438) - Rename fns
Rng::gen_range
torandom_range
,gen_bool
torandom_bool
,gen_ratio
torandom_ratio
(#1505) - Annotate panicking methods with
#[track_caller]
(#1442, #1447)
API changes: RNGs
- Fix
<SmallRng as SeedableRng>::Seed
size to 256 bits (#1455) - Remove first parameter (
rng
) ofReseedingRng::new
(#1533)
API changes: Sequences
- Split trait
SliceRandom
intoIndexedRandom
,IndexedMutRandom
,SliceRandom
(#1382) - Add
IndexedRandom::choose_multiple_array
,index::sample_array
(#1453, #1469)
API changes: Distributions: renames
- Rename module
rand::distributions
torand::distr
(#1470) - Rename distribution
Standard
toStandardUniform
(#1526) - Move
distr::Slice
->distr::slice::Choose
,distr::EmptySlice
->distr::slice::Empty
(#1548) - Rename trait
distr::DistString
->distr::SampleString
(#1548) - Rename
distr::DistIter
->distr::Iter
,distr::DistMap
->distr::Map
(#1548)
API changes: Distributions
- Relax
Sized
bound onDistribution<T> for &D
(#1278) - Remove impl of
Distribution<Option<T>>
forStandardUniform
(#1526) - Let distribution
StandardUniform
support allNonZero*
types (#1332) - Fns
{Uniform, UniformSampler}::{new, new_inclusive}
return aResult
(instead of potentially panicking) (#1229) - Distribution
Uniform
implementsTryFrom
instead ofFrom
for ranges (#1229) - Add
UniformUsize
(#1487) - Remove support for generating
isize
andusize
values withStandardUniform
,Uniform
(except viaUniformUsize
) andFill
and usage as aWeightedAliasIndex
weight (#1487) - Add impl
DistString
for distributionsSlice<char>
andUniform<char>
(#1315) - Add fn
Slice::num_choices
(#1402) - Add fn
p()
for distributionBernoulli
to access probability (#1481)
API changes: Weighted distributions
- Add
pub
modulerand::distr::weighted
, movingWeightedIndex
there (#1548) - Add trait
weighted::Weight
, allowingWeightedIndex
to trap overflow (#1353) - Add fns
weight, weights, total_weight
to distributionWeightedIndex
(#1420) - Rename enum
WeightedError
toweighted::Error
, revising variants (#1382) and mark as#[non_exhaustive]
(#1480)
API changes: SIMD
- Switch to
std::simd
, expand SIMD & docs (#1239)
Reproducibility-breaking changes
- Make
ReseedingRng::reseed
discard remaining data from the last block generated (#1379) - Change fn
SmallRng::seed_from_u64
implementation (#1203) - Allow
UniformFloat::new
samples andUniformFloat::sample_single
to yieldhigh
(#1462) - Fix portability of distribution
Slice
(#1469) - Make
Uniform
forusize
portable viaUniformUsize
(#1487) - Fix
IndexdRandom::choose_multiple_weighted
for very small seeds and optimize for large input length / low memory (#1530)
Reproducibility-breaking optimisations
- Optimize fn
sample_floyd
, affecting output ofrand::seq::index::sample
andrand::seq::SliceRandom::choose_multiple
(#1277) - New, faster algorithms for
IteratorRandom::choose
andchoose_stable
(#1268) - New, faster algorithms for
SliceRandom::shuffle
andpartial_shuffle
(#1272) - Optimize distribution
Uniform
: use Canon's method (single sampling) / Lemire's method (distribution sampling) for faster sampling (breaks value stability; #1287) - Optimize fn
sample_single_inclusive
for floats (+~20% perf) (#1289)
Other optimisations
Other
- Add
Cargo.lock.msrv
file (#1275) - Reformat with
rustfmt
and enforce (#1448) - Apply Clippy suggestions and enforce (#1448, #1474)
- Move all benchmarks to new
benches
crate (#1329, #1439) and migrate to Criterion (#1490)
Documentation
- Improve
ThreadRng
related docs (#1257) - Docs: enable experimental
--generate-link-to-definition
feature (#1327) - Better doc of crate features, use
doc_auto_cfg
(#1411, #1450)
All PRs
- update Miri CI config by @RalfJung in #1223
- fix typo by @cuishuang in #1228
- Remove unused fields by @vks in #1184
- Make
CryptoRngCore
trait implyCryptoRng
as well by @cbeck88 in #1230 - Deterministic Rayon monte carlo example by @masonk in #1236
- small deterministic example update by @TheIronBorn in #1240
- switch to std::simd, expand SIMD & docs by @TheIronBorn in #1239
- optimize simd widening mul by @TheIronBorn in #1247
- Mention disabling getrandom for wasm32-unknown-unknown in README by @golddranks in #1250
- Bump MSRV to 1.51.0 by @dhardy in #1246
- rand_core: update CHANGELOG for 0.6.4 by @dhardy in #1253
- Update listed rand_core version number by @atouchet in #1254
- Doc: improve random, thread_rng, ThreadRng docs by @dhardy in #1257
- Clarify documentation of
choose_weighted(_mut)
mentioning accurate behavior with floats by @ISibboI in #1245 - clarify shuffle docs by @RalfJung in #1259
- fix outdated choose_multiple_weighted docs by @TheIronBorn in #1237
- Update GitHub Actions by @dhardy in #1263
- Fix typo by @yaronf in #1264
- Remove redundant bounds by @steffahn in #1207
- SmallRng uses wrong seed_from_u64 implementation by @ironhaven in #1203
- gh-pages action: add id-token write permission by @dhardy in #1265
- Bump MSRV to 1.56 (Edition 2021) by @dhardy in #1269
- fill_via_chunks: mutate src on BE (small optimisation) by @dhardy in #1182
- Add read_adapter to avoid dynamic dispatch by @SUPERCILEX in #1267
- GitHub Workflows security hardening by @sashashura in #1274
- Add Criterion as dev-dependency, fix CI for MSRV and minimal-versions by @dhardy in #1275
- use partition_point in WeightedIndex by @TheIronBorn in #1276
- Simpler and faster implementation of Floyd's F2 by @ciphergoth in #1277
- Relax
Sized
bound onDistribution<T> for &D
by @ChayimFriedman2 in #1278 - Added new versions of choose and choose_stable by @wainwrightmark in #1268
- Performance improvements for
shuffle
andpartial_shuffle
by @wainwrightmark in #1272 - Add note about floating point weights in update_weights docs by @arya2 in #1280
- Make
Uniform
constructors return a result by @vks in #1229 - Poisson returns -1 for small lambda by @tearne in #1284
- Rework CryptoRng by @newpavlov in #1273
- Don't run the random write test by @SUPERCILEX in #1294
- Poisson distribution falls into an infinite loop for parameter Ξ»=β by @Thopic in #1291
- Use const generics in Dirichlet by @Armavica in #1292
- Uniform sampling: use Canon's method by @dhardy in #1287
- StepRng: better documentation of outputs for other types by @dhardy in #1304
- Simplify slice size calcuation by @schubart in #1308
- rand_distr: Fix dirichlet sample method for small alpha. by @WarrenWeckesser in #1209
- Uniform float improvements by @dhardy in #1289
- Re-introduce Rng::gen_iter by @dhardy in #1305
- fix feature typo by @ihciah in #1316
- ReseedingRng: fix doc comment on reseeding behavior after UNIX fork by @LiosK in #1317
- impl TrustedLen is unsafe by @dhardy in #1318
- Replace tab character with spaces in poisson.rs. by @WarrenWeckesser in #1320
- Fix infinite loop in Binomial distribution by @benjamin-lieser in #1325
- Add
DistString
impl toUniform
andSlice
by @aobatact in #1315 - Add
--generate-link-to-definition
option when building on docs.rs by @GuillaumeGomez in #1327 - Add tests for
Uniform::try_from
with invalid ranges by @vks in #1331 - Implement Standard support for signed NonZero* types by @elichai in #1332
- fix partial_shuffle documentation by @TheIronBorn in #1335
- Improve doc of slice and iterator "choose" methods by @dhardy in #1343
- Use cfg(panic = unwind) instead of a check for wasm32 to see if unwinding is supported by @bjorn3 in #1341
- Simplify macro implementation for tuples by @Lucretiel in #1340
- Correcting method name in comment by @OldEnglishSheepdog in #1350
- Mention that
gen_range
may overflow for floats by @vks in #1351 - Use zerocopy to replace some unsafe code by @joshlf in #1349
- Support using std without getrandom or rand_chacha by @SUPERCILEX in #1354
- Fix clippy warnings by @vks in #1363
- Add example for initializing a PCG RNG by @vks in #1352
- Trap weighted index overflow by @dhardy in #1353
- Replace SeedableRng impl for SmallRng with inherent fns by @dhardy in #1368
- Allow new warning on recent nightly versions by @bjorn3 in #1376
- Add WeightedIndexTree to rand_distr by @xmakro in #1372
- Add dependabot by @oriontvv in #1383
- Bump actions/configure-pages from 2 to 4 by @dependabot in #1389
- Bump actions/checkout from 3 to 4 by @dependabot in #1386
- Update zerocopy; trim unused methods by @dhardy in #1393
- Bump actions/cache from 3 to 4 by @dependabot in #1385
- Update special requirement from 0.8.1 to 0.10.3 by @dependabot in #1384
- Rename WeightedError β WeightError; add IndexedRandom, IndexedMutRandom by @dhardy in #1382
- Update serde_with requirement from 1.14.0 to 3.6.1 by @dependabot in #1392
- Bump actions upload-pages-artifact, deploy-pages by @dhardy in #1396
- Prepare rand 0.9.0-alpha.0 by @dhardy in #1395
- Disable rand_pcg's dev dependency on rand by @dhardy in #1397
- Add path for benchmark by @dhardy in #1398
- Fix redundant import warnings by @MichaelOwenDyer in #1405
- Add .choices() method to the Slice distribution by @JustusFluegel in #1402
- chore: fix typos by @acceptacross in #1407
- document more crate features by @TheIronBorn in #1411
- Update zerocopy requirement from =0.8.0-alpha.5 to =0.8.0-alpha.6 by @dependabot in #1401
- Update average requirement from 0.13 to 0.14 by @dependabot in #1388
- Remove automatic (delayed) reseed-on-fork by @dhardy in #1379
- Prepare 0.9.0-alpha.1 by @dhardy in #1413
- Use Simd::wrapping_neg by @dhardy in #1414
- Bump the MSRV to 1.61.0 by @dhardy in #1416
- Cleaner README, remove MSRV shields by @dhardy in #1417
- Update average requirement from 0.14 to 0.15 by @dependabot in #1426
- Add methods weight, weights, and total_weight to weighted_index.rs by @MichaelOwenDyer in #1420
- Bump actions/configure-pages from 4 to 5 by @dependabot in #1427
- Put macro
x86_intrinsic_impl
behind x86 configuration by @MichaelOwenDyer in #1431 - Optimize imports by @MichaelOwenDyer in #1430
- rand_distr/std_math: add note regarding other dependents by @dhardy in #1421
- Add "bug report" issue template by @dhardy in #1436
- Upgrade criterion by @dhardy in #1439
- Upgrade criterion by @vks in #1329
- Rename
Rng::gen
toRng::random
by @vks in #1438 - Add #[track_caller] to methods which panic by @josephlr in #1442
- Make WeightedTree::try_sample public by @xmakro in #1444
- Use zerocopy 0.7.33, not 0.8.0-alpha by @joshlf in #1446
- Add
TryRngCore
andTryCryptoRng
traits by @newpavlov in #1424 - Update Panic documentation and #[track_caller] by @josephlr in #1447
- Apply rustfmt and fix Clippy warnings by @newpavlov in #1448
- Rename
doc_cfg
todocsrs
and usedoc_auto_cfg
by @newpavlov in #1450 - Tweak docs CI job by @newpavlov in #1451
- Revise crate doc for rand_pcg, rand_chacha by @dhardy in #1454
- Revise RNG docs; enable small_rng by default by @dhardy in #1455
- Fix benches CI job by @newpavlov in #1456
- Fix Nightly Clippy lints by @newpavlov in #1457
- Add IndexedRandom::choose_multiple_array, index::sample_array by @dhardy in #1453
- Add distribution plots to
rand_distr
documentation by @MichaelOwenDyer in #1434 rand_distr
: Rename Zeta parameter froma
tos
by @MichaelOwenDyer in #1466- rand_distr: split gamma module by @dhardy in #1464
- Revise pert by @dhardy in #1452
- UniformFloat: allow inclusion of high in all cases by @dhardy in #1462
- Fix some typos. by @waywardmonkeys in #1472
- Fix
clippy::doc_markdown
warnings. by @waywardmonkeys in #1474 - Portability fixes by @dhardy in #1469
- rand::distributions -> distr; split uniform module by @dhardy in #1470
- Rename
serde1
feature toserde
. by @waywardmonkeys in #1477 - Document small issues by @dhardy in #1479
- Doc issues by @dhardy in #1480
- Migrate remaining benchmarks to Criterion by @dhardy in #1490
- Require SeedableRng::Seed to impl Clone by @clarfonthey in #1491
- No usize except uniform by @dhardy in #1487
- Poisson: split Knuth/Rejection methods by @dhardy in #1493
- Poisson u64 sampling by @benjamin-lieser in #1498
- Rename gen_iter β random_iter, misc.. by @dhardy in #1500
- Make sure BTPE is not entered when np < 10 by @benjamin-lieser in #1484
- Remove some unsafe, update to zerocopy 0.8.0 by @joshlf in #1502
- Improve SmallRng initialization performance by @arthurprs in #1482
- Cdf testing with Kolmogorov Smirnov by @benjamin-lieser in #1494
- rand_core: add blanket impl of TryRngCore for RngCore by @newpavlov in #1499
- thread_rng() β rand::rng() by @dhardy in #1506
- Fix new Clippy lints by @newpavlov in #1511
- Weibull doc numerics warning by @benjamin-lieser in #1509
- Rng renames: gen_ β random_ by @dhardy in #1505
- Add
p()
forBernoulli
by @marcpabst in #1481 - Use explicit features rather than implicit. by @waywardmonkeys in #1473
- Add more KolmogorovβSmirnov test by @JamboChen in #1504
- Remove u64 support for Poisson by @dhardy in #1517
- README: rand is not a crypto library by @dhardy in #1514
- add
rand::range
, random_bool, random_iter, random_ratio, fill as top-level helper functions by @oconnor663 in #1488 - Zipf: let n have type F by @dhardy in #1518
- Hypergeo fix by @benjamin-lieser in #1510
- Move ks by @benjamin-lieser in #1525
- Rename
Standard
βStandardUniform
by @dhardy in #1526 - Remove rng parameter of ReseedingRng::new by @dhardy in #1533
- remove conditional compilation around using core by @ComputerDruid in #1534
- Remove SmallRng::from_thread_rng by @dhardy in #1532
- Bump the MSRV to 1.63.0 by @dhardy in #1536
- Make getrandom a non-pub dep; rename feature to os_rng by @dhardy in #1537
- Add KS tests for weighted sampling by @dhardy in #1530
- Prepare 0.9.0-beta.0 by @dhardy in #1535
- Adjust GH Actions by @dhardy in #1538
- Fix docs.rs build options by @dhardy in #1539
- Update: getrandom v0.3.0 rc.0 by @dhardy in #1541
- Fix test status badges by @atouchet in #1544
- Thread rng by @dhardy in #1547
- Re-org with distr::slice, distr::weighted modules by @dhardy in #1548
- Enable
stdarch_x86_avx512
for cpu hasavx512bw
by @serendipity-crypto in #1551 - Prepare 0.9.0 release by @dhardy in #1558
New Contributors
- @cuishuang made their first contribution in #1228
- @cbeck88 made their first contribution in #1230
- @masonk made their first contribution in #1236
- @golddranks made their first contribution in #1250
- @atouchet made their first contribution in #1254
- @ISibboI made their first contribution in #1245
- @yaronf made their first contribution in #1264
- @steffahn made their first contribution in #1207
- @ironhaven made their first contribution in #1203
- @SUPERCILEX made their first contribution in #1267
- @sashashura made their first contribution in #1274
- @ciphergoth made their first contribution in #1277
- @ChayimFriedman2 made their first contribution in #1278
- @wainwrightmark made their first contribution in #1268
- @arya2 made their first contribution in #1280
- @tearne made their first contribution in #1284
- @Thopic made their first contribution in #1291
- @schubart made their first contribution in #1308
- @WarrenWeckesser made their first contribution in #1209
- @ihciah made their first contribution in #1316
- @LiosK made their first contribution in #1317
- @benjamin-lieser made their first contribution in #1325
- @aobatact made their first contribution in #1315
- @elichai made their first contribution in #1332
- @bjorn3 made their first contribution in #1341
- @OldEnglishSheepdog made their first contribution in #1350
- @joshlf made their first contribution in #1349
- @xmakro made their first contribution in #1372
- @oriontvv made their first contribution in #1383
- @dependabot made their first contribution in #1389
- @MichaelOwenDyer made their first contribution in #1405
- @JustusFluegel made their first contribution in #1402
- @acceptacross made their first contribution in #1407
- @waywardmonkeys made their first contribution in #1472
- @clarfonthey made their first contribution in #1491
- @arthurprs made their first contribution in #1482
- @marcpabst made their first contribution in #1481
- @JamboChen made their first contribution in #1504
- @oconnor663 made their first contribution in #1488
- @ComputerDruid made their first contribution in #1534
- @serendipity-crypto made their first contribution in #1551
Full Changelog: 0.8.5...0.9.0