167 Commits

Author SHA1 Message Date
Diggory Hardy
8225d948b1
Rng renames: gen_ → random_ (#1505) 2024-10-16 14:45:36 +01:00
Diggory Hardy
f5185d91fa
thread_rng() → rand::rng() (#1506)
- Rename `rand::thread_rng()` → `rand::rng()`
- Remove `thread_rng()` and `random()` from the prelude
2024-10-11 08:51:21 +01:00
Artyom Pavlov
0fba9401c4
rand_core: add blanket impl of TryRngCore for RngCore (#1499)
This PR removes the hacky `impl_try_rng_from_rng_core` and
`impl_try_crypto_rng_from_crypto_rng` macros and replaces them with
blanket impls of `TryRngCore` for `RngCore` and `TryCryptoRng` for
`CryptoRng`.

This change means that `TryRngCore`/`TryCryptoRng` no longer can have
blanket impls for `&mut R` and `Box<R>`. But I think it should be
tolerable since most users will be using `RngCore`/`CryptoRng`, which
have blanket impl for `DerefMut` (it covers both `&mut R` and `Box<R>`).
2024-10-09 13:27:07 +03:00
Arthur Silva
d1f961c4be
Improve SmallRng initialization performance (#1482) 2024-10-07 12:12:40 +01:00
Diggory Hardy
66b11eb17b
Rename gen_iter → random_iter, misc.. (#1500)
This extracts the non-inherent-methods stuff from #1492.
2024-10-01 14:59:11 +01:00
Diggory Hardy
f2638201ff
Poisson: split Knuth/Rejection methods (#1493) 2024-09-23 18:02:25 +01:00
Diggory Hardy
ef052ec539
No usize except uniform (#1487)
- Add UniformUsize
- Support ..end and ..=ub range syntax for unsigned ints
2024-09-09 08:33:43 +01:00
Diggory Hardy
9e030aa221
Migrate remaining benchmarks to Criterion (#1490)
Translate everything still using the old test harness to Criterion.
2024-09-06 09:07:47 +01:00
Diggory Hardy
2d5948d264
rand::distributions -> distr; split uniform module (#1470) 2024-07-23 14:14:11 +01:00
Artyom Pavlov
1b762b2867
Apply rustfmt and fix Clippy warnings (#1448) 2024-05-09 07:50:08 +01:00
Artyom Pavlov
fba5521f0f
Add TryRngCore and TryCryptoRng traits (#1424)
This reworks fallibility, replacing the fixed `Error` type.
2024-05-08 14:10:32 +01:00
Vinzent Steinberg
4f8257a986
Rename Rng::gen to Rng::random (#1438) 2024-04-29 19:41:10 +01:00
Diggory Hardy
e55b1f6ee5 Merge rand_distr/benches into benches 2024-04-27 08:59:58 +01:00
Diggory Hardy
24b84a09a1 Move Criterion benches to benches/src 2024-04-27 08:46:09 +01:00
Diggory Hardy
3c0661b804 Rename rand_benches -> benches 2024-04-27 08:46:09 +01:00
Vinzent Steinberg
6f917e1f16 Move rand benches to their own crate 2024-04-26 14:21:28 +02:00
Michael Dyer
bca078e929
Optimize imports (#1430) 2024-04-05 16:04:30 +01:00
Diggory Hardy
4cbbb340ad
Remove automatic (delayed) reseed-on-fork (#1379)
* benches/generators.rs: standardize thread_rng benchmarks
* Remove cfgs from examples
* Remove ReadRng
* Add ThreadRng::reseed and doc to use
* Remove fork protection from ReseedingRng; remove libc dep
* Enable ReseedingRng without std
* Move ReseedingRng up; remove module rand::rngs::adapter
2024-03-18 17:41:15 +00:00
Diggory Hardy
1db3aa416c
Replace SeedableRng impl for SmallRng with inherent fns (#1368)
* Simplify redundant doc-link

* Remove impl of SeedableRng for SmallRng

* Fix SeedableRng::Seed type for StdRng

* SmallRng: do not expect thread_rng

* Make SmallRng::from_thread_rng infallible

* Fix benchmarks (SmallRng does not have from_entropy)
2024-01-05 10:58:22 +00:00
Vinzent Steinberg
c427cff1d5 Fix clippy warnings 2023-12-14 08:50:57 +01:00
Vinzent Steinberg
026292d316
Merge branch 'master' into uniform-float 2023-05-01 16:39:12 +02:00
Diggory Hardy
22d0756b68
Uniform sampling: use Canon's method, Lemire's method (#1287)
Also:

* Add uniform distribution benchmarks
* Add "unbiased" feature flag
* Fix feature simd_support
* Uniform: impl PartialEq, Eq where possible
* CI: benches now require small_rng; build-test unbiased
2023-03-24 12:29:15 +00:00
Diggory Hardy
8d98d4531d Bench uniform_float: better grouping of plots
Also avoid using internal API of Uniform distribution.
2023-03-18 09:54:12 +00:00
Diggory Hardy
95b366ff53 Add uniform_float benchmark
Note: sample_single and sample_single_inclusive use
different code paths for sampling.
2023-02-21 12:58:18 +00:00
Vinzent Steinberg
7d73990096
Make Uniform constructors return a result (#1229)
* Forbid unsafe code in crates without unsafe code

This helps tools like `cargo geiger`.

* Make `Uniform` constructors return a result

- This is a breaking change.
- The new error type had to be made public, otherwise `Uniform` could
  not be extended for user-defined types by implementing
  `UniformSampler`.
- `rand_distr` was updated accordingly.
- Also forbid unsafe code for crates where none is used.

Fixes #1195, #1211.

* Address review feedback
* Make `sample_single` return a `Result`
* Fix benchmarks
* Small fixes
* Update src/distributions/uniform.rs
2023-02-06 10:55:22 +00:00
Mark Wainwright
4bde8a0adb
Performance improvements for shuffle and partial_shuffle (#1272)
* Made shuffle and partial_shuffle faster
* Use criterion benchmarks for shuffle
* Added a note about RNG word size
* Tidied comments
* Added a debug_assert
* Added a comment re possible further optimization
* Added and updated copyright notices
* Revert cfg mistake
* Reverted change to mod.rs
* Removed ChaCha20 benches from shuffle
* moved debug_assert out of a const fn
2023-01-08 16:14:26 +00:00
Mark Wainwright
1e96eb4593
Added new versions of choose and choose_stable (#1268)
* Added new versions of choose and choose_stable

* Removed coin_flipper tests which were unnecessary and not building on ci

* Performance optimizations in coin_flipper

* Clippy fixes and more documentation

* Added a correctness fix for coin_flipper

* Update benches/seq.rs

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>

* Update benches/seq.rs

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>

* Removed old version of choose and choose stable and updated value stability tests

* Moved sequence choose benchmarks to their own file

* Reworked coin_flipper

* Use criterion for seq_choose benches

* Removed an old comment

* Change how c is estimated in coin_flipper

* Revert "Use criterion for seq_choose benches"

This reverts commit 23395391370ab95694558be90686eb16494e590a.

* Added seq_choose benches for smaller numbers

* Removed some unneeded lines from seq_choose

* Improvements in coin_flipper.rs

* Small refactor of coin_flipper

* Tidied comments in coin_flipper

* Use criterion for seq_choose benchmarks

* Made choose not generate a random number if len=1

* small change to IteratorRandom::choose

* Made it easier to change seq_choose benchmarks RNG

* Added Pcg64 benchmarks for seq_choose

* Added TODO to coin_flipper

* Changed criterion settings in seq_choose

Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>
2023-01-05 10:49:33 +00:00
Adam Reichold
f44ea42089 Extend generator benchmarks to include the newly added Pcg64Dxsm variant. 2021-12-06 13:41:05 +01:00
Brandon H. Gomes
1544c728cd
fix no_std/alloc/std compatibility issues
- using min_const_gen on no_std fails to compile because of a bad import
- sample_efraimidis_spirakis only requires alloc but it was marked with
  a std requirement
2021-09-04 18:33:39 -04:00
Vinzent Steinberg
067238f057
Remove rand_hc (#1156)
* Remove `rand_hc`

We no longer need it for `rand`, so it can be moved to the `rngs`
repository.
2021-08-05 14:59:07 +02:00
Vinzent Steinberg
1b8eaf23ea rand: Fix clippy warnings 2021-05-08 21:37:15 -03:00
Zachary Neely
9b4df3bb0b Add choose_multiple_weighted, tests, and benchmarks 2020-08-27 18:21:07 +02:00
Vinzent Steinberg
bbb0dff53c Fix benchmarks 2020-08-05 13:25:25 +02:00
Vinzent Steinberg
98b915feed Change gen_range to accept Range types
This adds support for `Rng::range(a..b)` and `Rng::range(a..=b)`,
replacing `Rng::range(a, b)`. `a` and `b` must now implement
`PartialEq`.

This is a breaking change. In most cases, replacing
`Rng::gen_range(a, b)` with `Rng::gen_range(a..b)` should be enough,
however type annotations may be necessary, and `a` and `b` can no longer
be references or SIMD types.

SIMD types are still supported by `UniformSampler::sample_single`.

Some clippy warnings were fixed as well.
2020-08-01 16:09:50 +02:00
Jonathan Giddy
c337164bbb Add a benchmark for UniformInt sample_single 2020-07-18 08:14:11 +01:00
Jonathan Giddy
1d54f1190f Move standard and uniform benchmarks to top-level crate 2020-07-08 07:45:01 +01:00
Diggory Hardy
571c9af9a6 Misc bench: add gen_1kb_u16_* 2020-02-28 15:34:08 +00:00
Diggory Hardy
92e07018e0 rustfmt: expression spacing (on the line) 2020-01-02 15:46:14 +00:00
Diggory Hardy
0f9500b725 rustfmt: function parameters 2020-01-02 15:46:14 +00:00
Diggory Hardy
1b3bcce9be rustfmt: closures 2020-01-02 15:46:14 +00:00
Diggory Hardy
363571540f rustfmt: method chaining 2020-01-02 15:46:14 +00:00
Diggory Hardy
4f1f0fce67 rustfmt: struct literals, if/for blocks 2020-01-02 15:46:14 +00:00
Diggory Hardy
477b47058f rustfmt: spacing, new-lines, trailing commas/semicolon 2020-01-02 15:46:14 +00:00
Diggory Hardy
ccb64dc0a0 rustfmt: attributes 2020-01-02 15:46:14 +00:00
Diggory Hardy
88aa915c66 rustfmt: use, mod statements and initial attributes 2020-01-02 15:46:14 +00:00
Diggory Hardy
2fc64ed429 Remove old RNG crates from benchmarks
Note: the init benches now use a different master RNG;
this appears to have little affect on results.
2019-09-20 16:47:46 +01:00
Vinzent Steinberg
ee6f33453e WeightedIndex: Clean up benchmark 2019-08-15 18:24:00 +02:00
Vinzent Steinberg
7351358e5a Benchmark creation vs. modification of WeightedIndex 2019-08-14 15:57:14 +02:00
Diggory Hardy
2dca83d861 Add inlining for StepRng 2019-06-27 10:01:12 +01:00
Vinzent Steinberg
8521f85b31 Fix benchmarks 2019-06-21 17:58:05 +02:00