$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] Simple question about boost::random
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-13 18:06:24
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