
AMDG Zachary Turner wrote:
I think I'm overlooking something very simple, but I'm trying to generate random numbers that are uniform over the open range of various data types. So I wrote this code:
template<typename T> struct rand_type_range { typedef boost::numeric::bounds<T> bounds;
static T generate() { static boost::uniform_int<T> range(bounds::lowest()+1, bounds::highest()-1); static boost::variate_generator<boost::minstd_rand&, boost::uniform_int<T> > generate(rng, range);
return generate(); } };
Using this with anything other than a boost::uint32_t gives lots of warnings, although the results turn out correct. Looking at the warnings it seems the infrastructure is still trying to use boost::uint32_t's for everything, so am I missing something simple?
boost::uint32_t comes from boost::minstd_rand. I'll fix the warnings shortly. BTW, boost::uniform_int has a number of problems in 1.39, which have been fixed in the trunk. Given the way that you're using it, I think that the only problem you will see is that the distribution is not quite uniform. In Christ, Steven Watanabe