From KitwarePublic
Revision as of 20:40, 20 December 2005 by Andy (talk | contribs)
Jump to navigationJump to search


Resolve platform dependancies with current random number generation. Many registration algorithms depend on random sampling, exactly where I came across the problem.


It would be great to standardize the random number generator to be sufficiently random, fast and generate the same sequences (from a given seed) across platforms. The discussion culminated with a post: I'm not sure any action happened on the suggestions.

More information on mailing list under "random number generator".

Mersenne Twister

It may be worth following the thread A stable portable may also be obtained from

Boost library

The Boost site has a good library for random generators:

Among others, it contains an implementation of the Mersenne Twister. So it may be a helpful source for writing an itkMersenneTwister class, or something like that.

In a previous email to the ITK users mailing list I described some tests to check the actual 'randomness' of two random generators, vnl_sample (which is currently used in ITK) and vnl_random (which is in a more recent version of VXL):

It appeared that vnl_random is much better. What I didn't mention in this email, is that I also tested the MersenneTwister from the Boost library. It gave similar results as vnl_random.

So, I would say that the MersenneTwister indeed is a good option.

Current Status

MersenneTwister has been added to ITK. Its faster and from the tests that I have, much more random. I've committed some tests to ITK. See for instance In general, its anywhere from 1 to 30 times faster than the vnl counterparts depending on the platform.

I suggest future uses of random number generator requiring algorithms try to use MersenneTwister. It provides methods to get both Normal and uniform distributed random variables. ALso it will not suffer from re-seeding issues on cygwin etc as in

ITK: [Welcome | Site Map]