# Boost :

Subject: Re: [boost] How to generate a Bernuolli number
From: Henning Basold (h.basold_at_[hidden])
Date: 2009-03-31 06:58:11

Hi,

About your problem: just reuse the number generator and construct a new
instance of bernoulli_distribution with the new probability:

int main() {
double p = 0.5;
boost::mt19937 rng;
boost::bernoulli_distribution<> d(p);

typedef boost::variate_generator<
boost::mt19937&,
boost::bernoulli_distribution<>
> generator;

generator g(rng, d);

int time_steps = 2;

for(int i = 0; i < 10; ++i) {
// change probability every second step
if(i % time_step == 0){
// change probability by 0.1 every second step
p += 0.1;
g = generator(rng, boost::bernoulli_distribution<>(p));
}
std::cout << g() << std::endl;
}
}

This does not work in the case of the number generator because it is
declared as reference parameter.

Henning

Barco You schrieb:
> Hi,
>
> Continue this question.
> I want to have dynamic Bernoulli experiment, which has the p changed
> dynamically with time!
>
> How can I implement it? thanks!
>
> On Tue, Mar 31, 2009 at 4:12 PM, Barco You <barcojie_at_[hidden]> wrote:
>
>
>> Hi peter,
>>
>> Okay, I see now ,thanks!
>>
>>
>> On Tue, Mar 31, 2009 at 4:03 PM, Peter Bartlett <pete_at_[hidden]>wrote:
>>
>>
>>> Quoting Barco You <barcojie_at_[hidden]>:
>>>
>>> Hi,
>>>
>>>> Sorry, wait!!!
>>>> [...]
>>>>
>>>>
>>> In the first case one variate_generator is constructed and it is used 10
>>> times.
>>>
>>> In the second case 10 variate_generators are contructed and each used
>>> once. Since they are default constructed, they are each primed to return the
>>> same sequence. In particular they return the same first number, 0.
>>>
>>> Pete
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Unsubscribe & other changes:

>>>
>>>
>>
>> --
>> -------------------------------
>> Enjoy life!
>> Barco You
>>
>>
>
>
>
>