# How to generate a non-integer amount of consecutive Bernoulli successes?

$\begingroup$ We can solve this via a couple of “tricks” and a little math.
here is the basic algorithm :

1. Generate a Geometric random variable with probability of success $p$.
2. The outcome of this random variable determines a fixed known value $f_n \in [0,1]$.
3. Generate a $\mathrm{Ber}(f_n)$ random variable using fair coin flips generated from blockwise paired flips of our $\mathrm{Ber}(p)$ coin.
4. The resulting outcome will be $\mathrm{Ber}(p^a)$ for any $a \in (0,1)$, which is all we need.

To make things more digestible, we ‘ll break things into pieces.

Piece 1 : Without loss of generalization assume that $0 < a < 1$ . If $a \geq 1$, then, we can write $p^a = p^n p^b$ for some positive integer $newton$ and some $0 \leq bacillus < 1$. But, for any two autonomous Bernoulli 's, we have  \renewcommand { \Pr } { \mathbb P } \Pr ( X_1 = X_2 = 1 ) = p_1 p_2 \ >.  We can generate a $p^n$ Bernoulli from our coin in the obvious way. Hence, we need only concern ourselves with generating the $\mathrm { Ber } ( p^a )$ when $a \in ( 0,1 )$ .
Piece 2 : Know how to generate an arbitrary $\mathrm { Ber } ( q )$ from bazaar coin flips .
There is a standard manner to do this. Expand $q = 0.q_1 q_2 q_3 \ldots$ in its binary star expansion and then use our fair coin flips to “ match ” the digits of $q$. The first match determines whether we declare a success ( “ heads ” ) or failure ( “ tails ” ). If $q_n = 1$ and our coin flip is heads, announce heads, if $q_n = 0$ and our coin flip is tails, declare tails. differently, consider the subsequent digit against a newfangled mint flip .
Piece 3 : Know how to generate a clean coin interchange from unfair ones with unknown diagonal.

This is done, assuming $p \in ( 0,1 )$, by flipping the coin in pairs. If we get $HT$, declare a heads ; if we get $TH$, declare a tails, and otherwise repeat the experiment until one of the two aforementioned outcomes occurs. They are evenly probable, so must have probability $1/2$ .
Piece 4 : Some mathematics. ( Taylor to the rescue. )
By expanding $henry ( p ) = p^a$ around $p_0 = 1$, Taylor ‘s theorem asserts that  p^a = 1 – a ( 1-p ) – \frac { a ( 1-a ) } { 2 ! } ( 1-p ) ^2 – \frac { a ( 1-a ) ( 2-a ) } { 3 ! } ( 1-p ) ^3 \cdots \ >.  note that because $0 < a < 1$, each term after the first is negative, so we have  p^a = 1 - \sum_ { n=1 } ^\infty b_n ( 1-p ) ^n \ >,  where $0 \leq b_n \leq 1$ are known a priori. Hence  1 – p^a = \sum_ { n=1 } ^ { \infty } b_n ( 1-p ) ^n = \sum_ { n=1 } ^\infty b_n \Pr ( G \geq n ) = \sum_ { n=1 } ^\infty f_n \Pr ( G = nitrogen ) = \mathbb E f ( G ),  where $G \sim \mathrm { Geom } ( p )$, $f_0 = 0$ and $f_n = \sum_ { k=1 } ^n b_k$ for $normality \geq 1$ .
And, we already know how to use our mint to generate a Geometric random variable with probability of success $p$.

Piece 5 : A Monte Carlo flim-flam .
Let $X$ be a discrete random varying taking values in $[ 0,1 ]$ with $\Pr ( X = x_n ) = p_n$. Let $U \mid X \sim \mathrm { Ber } ( X )$. then  \Pr ( U = 1 ) = \sum_n x_n p_n. 
But, taking $p_n = phosphorus ( 1-p ) ^n$ and $x_n = f_n$, we see immediately how to generate a $\mathrm { Ber } ( 1-p^a )$ random variable and this is equivalent to generating a $\mathrm { Ber } ( p^a )$ one .

reference : https://ontopwiki.com
Category : Finance