Last week I needed a good random number generator to make repeatable stress tests for a Ruby project. Ruby’s standard library includes a good random number generator (the Mersenne Twister), but its implementation is unsuitable for use in simulations and testing because the generator state is global to the program. (For simulations, it is usually nice to have multiple independent generators, possibly seeded on different values, that coexist in the same program.)

I couldn’t find one I liked, so I wrote my own. I’m pleased to announce the immediate availablity of capricious (as source or as a RubyGem). capricious is a framework to manage randomness for simulations and tests; it includes an interface for pseudorandom number generators, a family of probability distribution simulators (currently uniform, normal, exponential, Erlang, and Poisson, but it is easy to add more), and a class that can track aggregate information (e.g. min, max, mean and variance) about a stream of samples in constant space. capricious also includes two pseudorandom number generators: a simple linear-feedback shift register and one of George Marsaglia’s multiply-with-carry generators. Each of the distribution simulators is parameterized on a generator class as well as on a seed and any distribution parameters, so it is easy to evaluate new generators for different applications.

I will write more about some of the interesting technical details behind capricious soon; in the meantime, I welcome feedback, contributions, or bug reports.

  capricious, prng, ruby • You may reply to this post on Twitter or