nlucaroni
nlucaroni

Reputation: 47944

Repeatability and the Random module across different versions of OCaml

I've been setting up a test-suite along with advancing the application my team is writing and today I came across a problem in how I was going to test scripts that get run through our application. We allow the user to set a seed for the Random module to allow repeatability in results (this is very important in a scientific application), I use this in our test suite to compare the stdout/stderr from a set of scripts with 'approved' runs.

In updating those scripts I noticed that all the scripts failed on certain machines. I soon discovered this was due to the Random module from version 3.12.0 changing the core function for generating random bits. Currently we run a number of versions of OCaml (including 3.13) across a number of environments (win32, osx, linux) and we would prefer to test against different versions of OCaml.

I would like to replace the Random module from 3.12.1 into our distribution to allow for consistency regardless of the version of OCaml the user is compiling against. But, the naive approach to drop the Random module in the source directory reports that the compiler found two files that define a module named Random.

Any suggestions on solving this issue? I realize I can rename Random to XRandom and then use that module to define what I need or include the standard library random module, but that would require changing every function call and allows developers to continue to (accidentally) use Random instead of the overloaded version. Is there a way to select a specific random module during compilation? Or maybe some other option I'm unaware of.

EDIT:

I just took the Random module from OCaml 3.12.1 and dropped it into my project, on compilation via OCamlbuild I got the following error message during linking (this the same error with OCaml 3.13.0+dev8, and pretty much what I expected when I did it),

Error: Files random.cmx and /opt/ocaml-3.12.1/lib/ocaml/stdlib.cmxa
       both define a module named Random

And the linking line is,

Upvotes: 1

Views: 175

Answers (1)

Thomas
Thomas

Reputation: 5048

You can indeed use your own XRandom module, and add module Random = XRandom at the top of your test files.

Unfortunately, I'm afraid there is no good and clean solution to your problem ...

Upvotes: 2

Related Questions