|
Boost Users : |
From: chun ping wang (cablepuff_at_[hidden])
Date: 2006-05-19 03:55:00
I have a simple question, is there a very fast and effecient way to generate
random numbers that are fast on the fly. The numbers are really randomize
and distorted...
/***************************************************
* generates a random number between a and b *
* @param a the starting range *
* @param b the integer ending range *
* @return N such that a <= N <= b *
**************************************************/
template <class T>
T randint(const T& a, const T& b)
{
BOOST_STATIC_ASSERT(boost::is_integral<T>::value);
assert (b >= a);
typedef boost::minstd_rand base_generator_type;
typedef boost::uniform_int<> distribution_type;
typedef boost::variate_generator<base_generator_type&, distribution_type>
gen_type;
base_generator_type generator(boost::numeric_cast<unsigned
long>(clock()));
gen_type ran_gen(generator, distribution_type(a, b));
for (int i = 0; i < 30000; ++i)
generator.seed(boost::numeric_cast<unsigned long>(clock()));
return ran_gen();
}
This works but is super slow... are there effective ways to do it...
Thanks.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net