Boost logo

Boost Users :

Subject: Re: [Boost-users] :typedef mt19937, normal_distribution, variate_generator & data storage into vector
From: It neophyte (phdlux85_at_[hidden])
Date: 2014-12-14 16:33:25


Hi Gordon

Thanks for your feedback.

"Getting 260 zeros and 260 values?" -> Correct, the printed result was
somehow messed up.

I've realized (ex-post) that assigning a size (260) to the vector
declaration, before the for loop (i =[0;260]) did not factually help.
In addition, i've figured out a little scope issue. Hopefully adding an
iterator (vector<double>::iterator) has ensured that all the vector
elements are fine following my fix.

cheers

On Sun, Dec 14, 2014 at 10:02 PM, Gordon Woodhull <gordon_at_[hidden]>
wrote:
>
>
>
>
> On Dec 14, 2014, at 10:52 AM, It neophyte <phdlux85_at_[hidden]> wrote:
>
> hi all,
>
> does someone know why my vstore vector returns a 0 value? any suggestion
> to improve the code would be appreciated.cheers.
> *aim*: *generating 260 random numbers following a standard normal
> distribution, then store the values into a vector (here: vstore)*
>
> vector<double>vstore;
> vstore.resize(260);
>
>
> I think you meant "reserve" here. Getting 260 zeros and 260 values?
>
>
> typedef mt19937 ALEA;
> typedef normal_distribution<double> STGAUSSIAN;
> typedef variate_generator<ALEA,STGAUSSIAN> GENALEA;
>
> ALEA ale;
> STGAUSSIAN stgauss(0,1);
> GENALEA gen(ale,stgauss);
>
> for (int i=0;i<=260;i++)
> {
> //cout<<gen()<<endl;
> //system("pause");
> vstore.push_back(gen());
> cout<<vstore[i]<<endl;
> }
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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