ocaml-batteries-team/batteries-included — pull request #270 by bergsoe (2012-06-05 10:36:52+00:00)
Title: BatRandom.enum_xyz determinism and independence issues

I've written a message to the mailing list on this subject (see https://lists.forge.ocamlcore.org/pipermail/batteries-discuss/2012-February/000172.html) and here is the implementation I am proposing. See also the commit message (included below).

---

This commit replaces the implementation of random enumerations in
BatRandom such that this comment in BatRandom.State becomes true:

> These functions are the same as the basic functions, except that they
> use (and update) the given PRNG state instead of the default one.

Currently the enumerations in BatRandom outside of BatRandom.State
construct their own PRNG state behind the back of the user. This is
problematic since the enumerations become unreproducible and since
different enumerations by accident may be constructed from identical or
near-identical states.

Because the state can now be modified from outside of the enumeration,
implementing a correct clone operation is no longer trivial. The same
not-really-correct implementation of BatRandom.State is used, and a
comment has been added warning people not to clone the enumerations.
(IMO a correct clone operation would be to raise an Infinite_enum
exception or to rely on BatEnum's default implementation of clone, but
this is beyond the scope of this commit.)