`Normal` is sampled many times into a histogram, which is then compared
to the expected probability density function. To make debugging easier,
sparklines of the expected distribution, the histogram, and their
difference are printed.
Currently, the test fails if the difference is significantly larger than
the expected error of the histogram bin. However, the error estimate
does not take the error in the normalization due to the finite width of
the histogram into account. This should not be a problem, as long as the
distribution is almost zero outside the range covered by the histogram.
In principle, this approach can be generalized to other distributions.
Let me start by saying that I'm far from an expert when it comes to unsafe code in Rust. However, if I read [RFC 1758](https://github.com/rust-lang/rfcs/blob/master/text/1758-repr-transparent.md) correctly, it it seems that `Array64` should be marked `repr(transparent)`. This is because I believe it is considered an implementation detail that single-element tuple structs currently have the same representation as its single field:
> As a matter of optimisation, eligible #[repr(Rust)] structs behave as if they were #[repr(transparent)] but as an implementation detail that can't be relied upon by users.
With the transparent representation, the `generate` method can safely cast the `Array64<u32>` argument:
```rust
// Fill slice of words by writing to equivalent slice of bytes, then fixing endianness.
self.state.refill4($rounds, unsafe {
&mut *(&mut *r as *mut Array64<u32> as *mut [u8; 256])
});
```
This fixes the following warnings (from rustc 1.51.1):
warning: panic message is not a string literal
--> rand_distr/tests/value_stability.rs:29:9
|
29 | assert_almost_eq!(self, rhs, 1e-6);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(non_fmt_panic)]` on by default
= note: this is no longer accepted in Rust 2021
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
warning: panic message is not a string literal
--> rand_distr/tests/value_stability.rs:34:9
|
34 | assert_almost_eq!(self, rhs, 1e-14);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this is no longer accepted in Rust 2021
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
warning: panic message is not a string literal
--> rand_distr/tests/value_stability.rs:380:9
|
380 | assert_almost_eq!(a, b, 1e-5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this is no longer accepted in Rust 2021
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
* Add additional comments on how to use the advance() function
* Use clone() for clarity instead of reusing a seed
* Compare the generator as a whole as opposed the next value in unit
tests