crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.48k stars 1.62k forks source link

Random specs do not test distribution #10556

Open kimburgess opened 3 years ago

kimburgess commented 3 years ago

Feature Request

The current random spec does not test distribution of any outputs. Specs for implementations should check direct output from the RNG, however this module provides a number of additional behaviours for generating values extrapolated from this, which are not tested deeply.

To help capture mistakes by simpletons it would be nice to improve this test coverage. This does not have to be exhaustive, but testing a small sample provide a useful bump to quality with minimal impact on spec run time.

As a basis this could be:

Happy to submit a PR for this if it's of use here.

konovod commented 3 years ago

Implementation spec should check that RNG algorithm is actually the one that is described (Mersenne\PCG\Wyrand\etc). If the algorithm is right, distribution checks are not needed, if it is wrong distribution checks are not enough (example - what if some algorithm ignores seed and always generate same sequence. Distribution check will pass, but algorithm is still unusable).

kimburgess commented 3 years ago

Completely agree with that for the direct RNG output (e.g.#next_u). This is for the functionality provided by the Random module that transforms this into different ranges and types.