#include "util/random.hh" #include #include // #include #include namespace util { namespace { /** Lock to protect randomizer. * * This module is implemented in terms of rand()/srand() from . * These functions are standard C, but they're not thread-safe. Scalability * is not worth much complexity here, so just slap a mutex around it. */ boost::mutex rand_lock; } // namespace void rand_init(unsigned int seed) { boost::lock_guard lock(rand_lock); srand(seed); } void rand_init() { rand_init(time(NULL)); } namespace internal { // This is the one call to the actual randomizer. All else is built on this. int rand_int() { boost::lock_guard lock(rand_lock); return std::rand(); } } // namespace internal } // namespace util