|
Boost : |
Subject: Re: [boost] How to generate a Bernuolli number
From: Barco You (barcojie_at_[hidden])
Date: 2009-03-31 03:18:04
Hi,
Sorry, wait!!!
int main() {
double p = 0.5;
boost::mt19937 rng;
boost::bernoulli_distribution<> d(p);
boost::variate_generator<
boost::mt19937&,
boost::bernoulli_distribution<>
> g(rng, d);
for(int i = 0; i < 10; ++i) {
std::cout << g() << std::endl;
}
}
This really works. but If I write this in a function:
int genB() {
double p = 0.5;
boost::mt19937 rng;
boost::bernoulli_distribution<> d(p);
boost::variate_generator<
boost::mt19937&,
boost::bernoulli_distribution<>
> g(rng, d);
return g() ;
}
int main(){
for(int i = 0; i < 10; ++i) {
std::cout << genB() << std::endl;
}
}
I'll got always 0.... Why?
On Tue, Mar 31, 2009 at 2:06 PM, Barco You <barcojie_at_[hidden]> wrote:
> Hi Steven,
>
> Fine now!
> Thanks a lot!
>
>
> On Tue, Mar 31, 2009 at 11:11 AM, Steven Watanabe <watanabesj_at_[hidden]>wrote:
>
>> AMDG
>>
>> Barco You wrote:
>>
>>> I call it 1000 time, and all output is 0.
>>>
>>>
>>
>> Works for me...
>>
>> #include <boost/random.hpp>
>> #include <iostream>
>>
>> int main() {
>> double p = 0.5;
>> boost::mt19937 rng;
>> boost::bernoulli_distribution<> d(p);
>> boost::variate_generator<
>> boost::mt19937&,
>> boost::bernoulli_distribution<>
>> > g(rng, d);
>>
>> for(int i = 0; i < 10; ++i) {
>> std::cout << g() << std::endl;
>>
>> }
>> }
>>
>> In Christ,
>> Steven Watanabe
>>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>
>
>
> --
> -------------------------------
> Enjoy life!
> Barco You
>
-- ------------------------------- Enjoy life! Barco You
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk