Discrete uniform distribution over two disjoint intervals

619 Views Asked by At

in my program I have a function uniform$(a,b)$ which returns a uniformly distributed integer from $[a,b]$. My task is to use this function in order to obtain a uniformly distributed integer from $[1,5] \cup [8,13]$. Simply dropping the result if my function returns $6$ or $7$ and using uniform$(1,13)$ again is no alternative for efficiency reasons.

I took a look at my Stochastics course documents and found that: if $X$ is uniformly distributed on $[-1,1]$ then $Y = a+bX$ is uniformly distributed on $[a-b,a+b]$. So I thought I could use this fact and maybe the sum of of two uniform$(a,b)$ results but I cannot figure out how to do this.

Could you please give me a hint?

1

There are 1 best solutions below

1
On

Run your function on $[1,11]$. If you get $6$, change it to $12$. If you get $7$, change it to $13$. No other technique can be computationally more efficient.