Replace calls to `Random.stuff` with `Random.State.stuff`
This issue is concerned with non-determinism in tests and benchmarks. This causes flakiness, prevents using frameworks such as ppx_expect
or others regression trace-based frameworks and induces non-reproducible benchmarks.
As can be seen from the examples, snoop and related benchmarks and samplers (including the MCMC based samplers) suffer from that issue.
The main cause is the use of PRNGs with non-configurable seeds:
- on the crypto side, especially from rust bindings relying directly on OS-based sources of entropy
- but the main problem is bad uses of the OCaml
Random
module, which has a baked-in prng state which is shared among all calls to functions such asRandom.int, Random.float
, etc.
The use of primitives from the Random
module should all go through the submodule Random.State
, passing explicit prng states.
A suggestion for the second point is to alias Random
to Random.State
in the Tezos stdlib (cc @raphael-proust). On the crypto side, this could maybe be fixed by relying on an deterministic API based on explicitly consuming bytes
to produce relevant values, delegating sampling those bytes to the user of the API (cc @dannywillems)
Since this is also somewhat related to tests, ccing @arvidnl