0
$\begingroup$

I'm interested in generating random numbers.

I have a distribution [for simplicity let it be uniform distribution] of some event occurrence, i.e. the event occurs between $1$ to $3$ times per year.

I know how to generate the distribution per year [at least c++ gives me this ability].

My question is

how should i generate the distribution of events per month?

I thought, that if I had let say $1$ event per year, then I could generate a real number from $0$ to $1$, and if it fall under $\frac{1}{12}$ I can decide that event occurred at this month.

But

how can I decide if and how many events occur per month given distribution?

$\endgroup$
1
$\begingroup$

If $X$ is a standard uniform random variable, i.e. $X\sim \mathcal{U}(0,1)$, then to generate a uniform integer between $A$ and $B$ you can calculate $$Y= A+ \lfloor BX\rfloor$$ where $\lfloor\cdot\rfloor$ is the floor operator. For instance, to pick a month randomly (with uniform distribution), you will have to set $A=1$ and $B=12$, and you will get $Y\in[1,12]$. That is, the month at which the event happens.

If the event happens $K$ times per year, then you can repeat this for $K$ times with $X_1, X_2,\cdots X_K$, and you will get $Y_1, Y_2,\cdots Y_K$. In a computer, you can do it as an array.

$\endgroup$
  • $\begingroup$ I like the change in approach, but it unfortunately able to produce like "one" occurrence of distribution $\endgroup$ – dEmigOd Sep 17 '18 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.