Boost logo

Boost :

From: michael toksvig (michaeltoksvig_at_[hidden])
Date: 2005-05-23 15:29:36


you really want to make some of those local variables static or you will get
decidedly unrandom behaviour :-)

regards,

/michael toksvig

"christopher diggins" <cdiggins_at_[hidden]> wrote in message
news:001e01c55fd1$393e6080$2b792518_at_heronnest...
> AFAICT the shortest way to emulate the std::rand() function using
> boost/random.hpp would be as follows:
>
> unsigned int longhand_boost_rand() {
> boost::mt19937 rng;
> boost::uniform_int<> dist(0, RAND_MAX);
> boost::variate_generator
> <
> boost::mt19937,
> boost::uniform_int<>
> > generator(rng, dist);
> return generator();
> }
>
> (apologies if I made any mistakes)
>
> I was wondering if there would be any reason not to provide a utility
> function which made it easier to write random number generators. For
> instance, the following:
>
> template<class Dist_T, class Rng_T>
> typename boost::variate_generator<Rng_T, Dist_T>::result_type
> generate_rand(Dist_T dist, Rng_T rng) {
> return boost::variate_generator<Rng_T, Dist_T>(rng, dist)();
> }
>
> would allow us to rewrite our rand function as follows.
>
> unsigned int shorthand_boost_rand() {
> return generate_rand(boost::uniform_int<>(0, RAND_MAX),
> boost::mt19937());
> }
>
> By the way, congratulations on an excellent product to the random.hpp
> team.
>
> --
> Christopher Diggins
> http://www.cdiggins.com
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk