Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::random distribution is not working within a custom class
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-07-08 13:10:12


Hi!

In addition to Steven's remark: May be it relates to minimal example, but
why do you need a member pointer here? And why don't you delete it?

I think that would be a better approach:

-----------------
random2.h
-----------------

#ifndef RANDOM_NG_H
#define RANDOM_NG_H

#include <stdint.h>
#include <boost/random.hpp>

class randomNumberGenerator
{
 public:
   randomNumberGenerator( const uint32_t s );

   double operator()() { return ran_boost(); }

 private:
   boost::mt19937 rng_mt_boost_;
   boost::uniform_01<boost::mt19937&, double> ran_boost_;
};

extern randomNumberGenerator ran2;

#endif

-----------------
random2.cpp
-----------------

#include <iostream>
#include <boost/random.hpp>

#include "random2.h"

randomNumberGenerator ran2;

randomNumberGenerator::randomNumberGenerator( const uint32_t s )
  : rng_mt_boost_()
  , ran_boost_(rng_mt_boost_)
{
 rng_mt_boost_.seed( s );
 std::cout << ran_boost_() << std::endl;
}

Regards,
Ovanes

On Wed, Jul 8, 2009 at 6:46 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:

> AMDG
>
> Oliver Fochler wrote:
>
>>
>>
> You're creating a local variable here, not initializing the
> member ran_boost.
> In Christ,
> Steven Watanabe
>
>



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