Change from simple use of std::rand() to use Boost.Random and specify a reasonable range so we don't run out of memory. Other general tidy up.