Commit Graph

2864 Commits

Author SHA1 Message Date
Vinzent Steinberg 89aac82568 Fix dead link 2020-08-28 21:37:24 +02:00
Vinzent Steinberg 5bf110b980 Don't use deprecated import path 2020-08-28 21:37:24 +02:00
Vinzent Steinberg a393403d08 Update outdated links 2020-08-28 21:37:24 +02:00
Vinzent Steinberg 42247d8616 Restrict rand::rngs::adapter to std
See #911.
2020-08-28 18:47:54 +02:00
Vinzent Steinberg fbcfa2261d Fix chacha performance
This reverts a change from #979 that introduced a massive performance
regression by disabling SIMD for `rand_chacha`.

Likely, the behavior of `ppv-lite86` should rather be fixed. This change
serves as a workaround until a fixed version is available.

Fixes #1017.
2020-08-28 18:07:38 +02:00
Vinzent Steinberg 8d0e1f4d48 StdRng: Switch to ChaCha12 (#1028) 2020-08-28 16:29:51 +01:00
Vinzent Steinberg 2c6c6b1be1 Update changelog 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 9577e0b1c9 Slightly improve test 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 5bd9dcf642 Delete dead code 2020-08-28 15:31:56 +02:00
Vinzent Steinberg e88f2cba06 Restore unsafe fill_via_chunks implementation for performance 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 9ccdffd095 Simplify code 2020-08-28 15:31:56 +02:00
Vinzent Steinberg dae0d96286 Check source size and prefer chunks_exact 2020-08-28 15:31:56 +02:00
Vinzent Steinberg ad08968b00 Use chunks_exact_mut for slightly better performance
The results from master, using unsafe code:
```
gen_bytes_chacha12:   2,733,838 ns/iter (+/- 181,694) = 374 MB/s
gen_bytes_chacha20:   4,339,602 ns/iter (+/- 237,793) = 235 MB/s
gen_bytes_chacha8:    1,918,279 ns/iter (+/- 103,581) = 533 MB/s
```

The results of the new code using `chunks_exact_mut` (this commit):
```
gen_bytes_chacha12:   3,049,147 ns/iter (+/- 220,631)   = 335 MB/s
gen_bytes_chacha20:   4,645,772 ns/iter (+/- 269,261)   = 220 MB/s
gen_bytes_chacha8:    2,214,954 ns/iter (+/- 1,745,600) = 462 MB/s
```

The results of using `chunks_mut` (before this commit):
```
gen_bytes_chacha12:   3,492,109 ns/iter (+/- 164,638) = 293 MB/s
gen_bytes_chacha20:   5,087,706 ns/iter (+/- 249,219) = 201 MB/s
gen_bytes_chacha8:    2,700,197 ns/iter (+/- 524,148) = 379 MB/s
```
2020-08-28 15:31:56 +02:00
Vinzent Steinberg 4bb5cfa485 Simplify macro 2020-08-28 15:31:56 +02:00
Vinzent Steinberg f87ef95344 Fix fill_via_chunks and add tests 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 089a63878e WeightedIndex: Fix serde test 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 786b95fa10 Simplify tests to address review feedback 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 1589af3543 Try to fix endianess issue 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 812e7b35f8 Simplify cfg logic
This is possible thanks to `alloc` being implied by `std` builds since
Rust 1.36.
2020-08-28 15:31:56 +02:00
Vinzent Steinberg 80801fb78e Avoid indexing 2020-08-28 15:31:56 +02:00
Vinzent Steinberg c3f0a30ddd Drop some unsafe code from rand_core
The necessary standard library functions were stabilized with Rust 1.34.
Our MSRV is 1.36.
2020-08-28 15:31:56 +02:00
Vinzent Steinberg dd4b018b23 Reenable alloc tests for MSRV 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 7555747c16 Bump MSRV to 1.36 2020-08-28 15:31:56 +02:00
Vinzent Steinberg 9a3f2f4e7a sample_weighted: Make sure the correct IndexVec is generated
Also add some tests.
2020-08-27 18:21:07 +02:00
Vinzent Steinberg 29e78c7b75 Get rid of "partition_add_index" feature
It offers nothing over the "nightly" feature and makes testing more
complicated.
2020-08-27 18:21:07 +02:00
Vinzent Steinberg 437f789b06 sample_weighted: Use less memory for length <= u32::MAX 2020-08-27 18:21:07 +02:00
Vinzent Steinberg 519eb70d43 Address review feedback 2020-08-27 18:21:07 +02:00
Vinzent Steinberg 45a2c390ca sample_weighted: Return early if amount is 0 2020-08-27 18:21:07 +02:00
Vinzent Steinberg 158df6c34a Undo reformatting 2020-08-27 18:21:07 +02:00
Zachary Neely 57d0cb0ad4 Don't use IntoIter when unnecessary and fix complexity documentation 2020-08-27 18:21:07 +02:00
Zachary Neely 330909be42 Don't use rustc features newer than 1.32 2020-08-27 18:21:07 +02:00
Zachary Neely a310f9720c Fix feature flags and use core for nostd compatibility 2020-08-27 18:21:07 +02:00
Zachary Neely 8890183f13 Mark new tests with the correct feature flags 2020-08-27 18:21:07 +02:00
Zachary Neely 9b4df3bb0b Add choose_multiple_weighted, tests, and benchmarks 2020-08-27 18:21:07 +02:00
Diggory Hardy cb493927e6 Use doc(cfg) to annotate feature-gated items (#1019)
* Use doc(cfg) to annotate feature-gated items
* Fix block RNG example
* Formatting (partial rustfmt run)
2020-08-27 10:20:28 +01:00
Vinzent Steinberg 27757fb229 Update changelog for rand_distr 0.3.0 (#1024)
Co-authored-by: Diggory Hardy <git@dhardy.name>
2020-08-27 08:39:09 +01:00
Tamir Duberstein 0f933f9c71 Correctly spell "implementation" 2020-08-06 18:29:01 +02:00
Vinzent Steinberg bbb0dff53c Fix benchmarks 2020-08-05 13:25:25 +02:00
Vinzent Steinberg 0610312c89 Alphanumeric samples bytes instead of chars
The corresponds more closely to the internally used types and can be
easily converted to a `char` via `From` and `Into`, while being more
flexible to use.

This is a breaking change.
2020-08-05 13:25:25 +02:00
qoh 7f321fa21f Impl Distribution<u8> for Alphanumeric
Sampling a random alphanumeric string by collecting chars (that are known to be ASCII) into a String involves re-allocation as String is encoding to UTF-8, via the example:

```rust
let chars: String = iter::repeat(())
        .map(|()| rng.sample(Alphanumeric))
        .take(7)
        .collect();
```

I wanted to get rid of the clearly unnecessary re-allocations in my applications, so I needed to be able to access to the ASCII characters as simple bytes. It seems like that was already what was going on inside Alphanumeric however, it was just internal.

This PR changes the `Distribution<char>` impl to provide `u8`s (which it generates internally) instead, and implements the previous `Distribution<char>` using it. One could then, for example, do this:

```rust
let mut rng = thread_rng();
let bytes = (0..7).map(|_| rng.sample(ByteAlphanumeric)).collect();
let chars = unsafe { String::from_utf8_unchecked(bytes) };
```
2020-08-05 13:25:25 +02:00
Vinzent Steinberg dca9cb53eb Avoid to give advice on password generation 2020-08-04 17:29:46 +02:00
Diggory Hardy e0395fd713 Condense advice on password generation 2020-08-04 17:29:46 +02:00
Jeff Burdges 2da40a3691 Remarks on passwrod generation
I suppose the code should go elsewhere.
2020-08-04 17:29:46 +02:00
Артём Павлов [Artyom Pavlov] 321ae3962b fix build without std/alloc features 2020-08-02 02:39:46 +02:00
Артём Павлов [Artyom Pavlov] a75317ea4a fix test 2020-08-02 02:39:46 +02:00
Артём Павлов [Artyom Pavlov] 7781769f04 remove weighted module, re-export WeightedAliasIndex to top level 2020-08-02 02:39:46 +02:00
Артём Павлов [Artyom Pavlov] 5cebc0c083 Rename alias_method::WeightedIndex to WeightedAliasIndex 2020-08-02 02:39:46 +02:00
Vinzent Steinberg c4dda363e3 Update changelogs (#1010) 2020-08-01 18:43:16 +01: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
Benjamin Saunders 17651c0855 Add UniformSampler::sample_single_inclusive
This includes a specialized implementation for integers.
2020-08-01 16:09:50 +02:00