trsl logo

Random Number Generators

Some of the classes in TRSL need random numbers. If a class needs only one random number (e.g. trsl::is_picked_systematic), it is generally possible to provide it directly. It's then up to the user to take care of the random generator.

Another possibility is to use TRSL-internal random capabilities, implemented using system random number generators. By default, the std::rand function is used.

The std::rand generator that comes with BSD systems (including MacOS X) has slight issues — e.g. some bits of the returned numbers are not usable. However, BSD systems provide a second, better random number generator through a function named ::random. This function will be used instead of std::rand if TRSL_USE_BSD_BETTER_RANDOM_GENERATOR is defined. In that case, seeding should be done through ::srandom. Note that in GNU/Linux systems, both std::rand and ::random use the same generator.

When relying on TRSL-internal std::rand/::random calls, the user is still responsible for seeding the random number generator.

© Copyright 2007-2011 Renaud Detry.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
Revised Wed Apr 6 16:30:07 2011. Logo