Who Cares
Who Cares

Reputation: 205

generating binary values using poisson distrubution in c++

the code I got from cpluscplus dot com is:

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator (seed);

std::poisson_distribution<int> distribution (0.5);

std::cout << "some Poisson-distributed results (mean=0.5): ";
for (int i=0; i<10; ++i)
  std::cout << distribution(generator) << " ";

std::cout << std::endl;

the mean was 5.2 and I changed it to 0.5 to generate 0 or 1. But it produces 2 or 3 sometimes. How can I limit that?

EDIT: I read what you said. I need poisson, and I need it as binary. Here is the why: I am working the topic "spectrum sensing in cognitive radio networks". All the paper I read, the authors say "I used poisson distribution to test my study". For people who don't know the topic: There is a Primary User (Licensed User) in the environment. And It uses a channel time to time. And there are also secondary users (unlicensed users) and they try to predict primary's time slot so they can jump in to the channel when the primary is off. So, to do this:

primaryUserTimeslotTable={1,1,1,0} //should be generated with poisson dist. (papers say)

and the same way (with same mean) we create this array for the each cognitive user.

Upvotes: 0

Views: 273

Answers (1)

mrmcgreg
mrmcgreg

Reputation: 2816

Lambda is the mean of a Poisson distribution, so 0.5 is lambda.

It doesn't make sense to 'limit' a Poisson distribution since the mean is just the expected value. You can have more or fewer successes.

Maybe you're looking for a Bernoulli distribution?

EDIT:

I did a quick google on "spectrum sensing in cognitive radio networks" and it looks like you're after a Poisson point process. If you have a Poisson point process with intensity lambda then events occur at a rate such that the expected number of events on any unit time interval is lambda.

Upvotes: 1

Related Questions