Page
Library
Module
Module type
Parameter
Class
Class type
Source
This library includes OCaml implementation of some pseudorandom number generators (PRNGs) designed by David Blackman and Sebastiano Vigna behind an interface that mimmics that of the Random module of the standard library.
The Xoshiro generators (for XOR/shift/rotate) are all-purpose generators (not cryptographically secure). Compared to the standard library, they:
xoshiro256++/xoshiro256** generators have a period of 2²⁵⁶-1.xoshiro256++/xoshiro256** pass the whole BigCrush test suite while the Random module of the standard library systematically fails some of the tests.The modules in this library are drop-in replacements of the Random module of the standard library. This means you can use Xoshiro everywhere where you would use Random. For instance:
Xoshiro.bits instead of Random.bitsint, bool, etc. and also for the State submodule)open Xoshiro instead of open Randommodule Random = Xoshiro at the beginning of every file.The library comes in two version: one using C bindings and the other written in pure OCaml. The C bindings are here for performances. They are usually around twice faster as their pure counterpart. The pure implementations come from applications which require it, eg. for programs that compile to JavaScript. The interface is the same, the only thing that changes is whether you depend on the library xoshiro.bindings or xoshiro.pure. By default, xoshiro depends on xoshiro.bindings.
For instance, say you have an executable crazyrandom which uses the standard Random module as source of randomness. You can easily switch to using Xoshiro instead by replacing all occurrences of Random in crazyrandom.ml by Xoshiro (a simple search and replace should do the trick). You can then compile your executable with a Dune file similar to:
(executable
(name crazyrandom)
(libraries xoshiro))Now you realise that you also need to compile for JavaScript. Sadly, C bindings will not work there. You can however keep the same file for crazyrandom.ml and change your Dune file to:
(executable
(name crazyrandom)
(libraries xoshiro.pure)
(modes js))You're done!
We recommend installing via OPAM with opam install xoshiro. Otherwise, make followed by make install should do the trick, provided you have the required dependencies.
Documentation is available online. It can also be built locally with make doc and by pointing a browser to doc/index.html.
The library comes with a set of tests and benchmarks. Tests are ran at every push to the repository. The tests include:
MakeRandom functors build the same interface as the standard library.It is easy to run other test batteries on generators. For instance, one can run BigCrush on xoshiro256++ by calling:
dune exec xoshiro256plusplus/test/crusher/crusher.exe -- --bigcrush --verboseThe benchmarks allow to compare various PRNGs from this library against each other and, more importantly, against the standard library. They can be ran using dune exec bench/run.exe. For xoshiro256++, we observe that the bindings are slightly slower than the standard library, and almost twice faster than the pure implementations.
xoshiro) in an interface similar to that of the standard library (although not exactly the same, contrary to what can be obtained with make-random).