Why Partition the Unit Interval?
Simulation often starts with a pseudo-random number that behaves like a draw from the uniform distribution on the unit interval. A Bernoulli outcome or a categorical outcome can be generated by assigning a portion of that interval to each possible result. The size of each portion is chosen to equal the probability of its result.
For a Bernoulli variable, the unit interval is divided into two regions: one for success and one for failure. For a categorical variable, the interval is divided into as many regions as there are categories. In either case, the key checks are that the regions cover the whole interval without overlapping and that each region has the required length.
Generating a Bernoulli Outcome
Let \(U\) be uniformly distributed on \([0,1)\). To generate a Bernoulli variable with success probability \(p\), assign success to the interval \([0,p)\) and failure to \([p,1)\). Equivalently, set \(B=1\) when \(U<p\), and \(B=0\) otherwise.
The rule follows directly from the uniform distribution: for any interval \([a,b)\) contained in \([0,1)\), the probability that \(U\) falls in that interval is its length, \(b-a\). Thus the success region has length \(p-0=p\), while the failure region has length \(1-p\). This proves that the generated variable has the specified Bernoulli distribution.
Worked Example: Simulating a Bernoulli Outcome
A hypothetical model assigns probability \(0.28\) to a specified event. Generate the event indicator using the uniform values \(0.07,\ 0.28,\ 0.41,\ 0.83,\ 0.99\). No interest-rate or mortality assumption is involved. The target distribution is Bernoulli with parameter \(p=0.28\), and each input is treated as a uniform variate on \([0,1)\).
Method. Use the success interval \([0,0.28)\). A value below \(0.28\) gives indicator 1; a value at or above \(0.28\) gives indicator 0.
For \(U=0.07\), \(0.07<0.28\), so the indicator is 1.
For \(U=0.28\), \(0.28\not<0.28\), so the indicator is 0. The interval convention assigns the boundary to failure.
For \(U=0.41,\ 0.83,\) and \(0.99\), each value is at least \(0.28\), so each indicator is 0. The generated sequence is therefore \(1,0,0,0,0\).
Check. The success region has length \(0.28\), and the failure region has length \(1-0.28=0.72\). Hence \(P(B=1)=0.28\) and \(P(B=0)=0.72\), as required. The method avoids the common boundary mistake of treating \(U=p\) as a success under a strict \(U<p\) rule.
Generating a Finite Categorical Outcome
Suppose the possible outcomes are \(c_1,\ldots,c_k\), with probabilities \(p_1,\ldots,p_k\). Put the categories in a chosen order and form cumulative probabilities. Define \(q_0=0\) and \(q_j=\sum_{r=1}^{j}p_r\) for \(j=1,\ldots,k\). Assign category \(c_j\) to the interval \([q_{j-1},q_j)\). The final cumulative probability is \(q_k=1\).
Each category has the specified probability because the length of its interval is \(q_j-q_{j-1}=p_j\). The intervals are adjacent, so they do not overlap; together they cover \([0,1)\), because \(q_0=0\) and \(q_k=1\). Therefore, exactly one category is selected for every \(U\) in \([0,1)\), and \(P(C=c_j)=p_j\).
Worked Example: Mapping Uniform Values to Four Categories
A hypothetical model has four outcomes, \(A,B,C,D\), with probabilities \(0.12,\ 0.23,\ 0.40,\ 0.25\), respectively. Use the uniform values \(0.05,\ 0.12,\ 0.34,\ 0.35,\ 0.74,\ 0.75,\ 0.91\) to select outcomes. No interest-rate or mortality assumption is involved; the target distribution is the stated categorical distribution, and \(U\) is uniform on \([0,1)\).
Method. First check the probabilities: \(0.12+0.23+0.40+0.25=1.00\). The cumulative boundaries are \(0,\ 0.12,\ 0.35,\ 0.75,\ 1.00\). Thus the intervals are \([0,0.12)\) for \(A\), \([0.12,0.35)\) for \(B\), \([0.35,0.75)\) for \(C\), and \([0.75,1)\) for \(D\).
The value \(0.05\) is in \([0,0.12)\), so it selects \(A\). The value \(0.12\) is in \([0.12,0.35)\), so it selects \(B\). The value \(0.34\) is also in \(B\)'s interval.
The value \(0.35\) is in \([0.35,0.75)\), so it selects \(C\). The value \(0.74\) also selects \(C\). The value \(0.75\) begins \(D\)'s interval, so it selects \(D\), as does \(0.91\). The selected sequence is \(A,B,B,C,C,D,D\).
Check. The four interval lengths are \(0.12,\ 0.35-0.12=0.23,\ 0.75-0.35=0.40,\) and \(1.00-0.75=0.25\). These are exactly the specified probabilities. The method avoids assigning a boundary value to both adjacent categories.
Weights, Zero Probabilities, and Endpoint Conventions
Sometimes a model gives nonnegative weights rather than probabilities. If the weights are \(w_1,\ldots,w_k\), and their sum \(W=\sum_{j=1}^{k}w_j\) is positive, convert them to probabilities using \(p_j=w_j/W\). The interval construction then uses these normalized probabilities. Weights themselves are not interval lengths unless they already sum to one.
A category with probability zero has an interval of length zero, so it cannot be selected when \(U\) is in \([0,1)\). If a category has probability one, its interval is the whole unit interval and all other categories have zero probability. These limiting cases agree with the definitions.
The half-open interval convention \([q_{j-1},q_j)\) makes assignments unambiguous, including when a supplied value equals a cumulative boundary. A continuous uniform variable has probability zero of taking any one exact boundary value, so changing the assignment of a boundary would not change the theoretical probabilities. Nevertheless, a simulation algorithm needs one consistent convention because computer-generated values are represented discretely. If a software generator can return 1, define how that endpoint is handled or use a generator whose outputs are in \([0,1)\).
For repeated independent outcomes, use a separate independent uniform variate for each draw. Each individual mapping has the required marginal distribution. If the uniform variates are dependent, the mapped outcomes need not be independent, even though each one may still have the required marginal probabilities.
Worked Example: Converting Relative Weights to Categories
A hypothetical three-outcome model assigns relative weights \(2,\ 5,\ 3\) to outcomes \(R,S,T\). Use uniform values \(0.19,\ 0.20,\ 0.69,\ 0.70,\ 0.99\) to select outcomes. No interest-rate or mortality assumption is involved. The target distribution is categorical, obtained by normalizing the stated weights, and \(U\) is uniform on \([0,1)\).
Method. The weight total is \(W=2+5+3=10\). Normalize each weight: \(p_R=2/10=0.20\), \(p_S=5/10=0.50\), and \(p_T=3/10=0.30\). The probabilities sum to \(1.00\).
The cumulative boundaries are \(0,\ 0.20,\ 0.70,\ 1.00\). Therefore, \(R\) corresponds to \([0,0.20)\), \(S\) to \([0.20,0.70)\), and \(T\) to \([0.70,1)\).
The value \(0.19\) selects \(R\). The value \(0.20\) is at the start of \(S\)'s interval, so it selects \(S\). The value \(0.69\) also selects \(S\). The value \(0.70\) is at the start of \(T\)'s interval, and \(0.99\) is also in that interval. The selected sequence is \(R,S,S,T,T\).
Check. The interval lengths are \(0.20,\ 0.70-0.20=0.50,\) and \(1.00-0.70=0.30\), matching the normalized probabilities. The method avoids the common mistake of treating the raw weights \(2,5,3\) as probabilities.
Common Exam Trap: Using Probabilities Instead of Cumulative Boundaries
For categorical sampling, the intervals are built from cumulative probabilities, not from the probability list used repeatedly as if each value were an independent cutoff. For example, with probabilities \(0.20,\ 0.50,\ 0.30\), the correct boundaries are \(0.20,\ 0.70,\ 1.00\). Using cutoffs \(0.20,\ 0.50,\ 0.30\) does not create consecutive, non-overlapping regions that cover the unit interval: the last cutoff even moves backward.
The correction is to add each probability to the total before it. The intervals are \([0,0.20)\), \([0.20,0.70)\), and \([0.70,1)\). Their lengths are \(0.20,\ 0.50,\) and \(0.30\). Always check both that the final boundary is one and that each interval length equals the probability of its assigned category.
Check Your Understanding
For each problem, use the half-open interval convention and assume uniform inputs on \([0,1)\).
- A Bernoulli model has success probability \(0.40\). Classify the inputs \(0.10,\ 0.40,\ 0.89\) as success or failure. (Answer: success, failure, failure.)
- Categories \(A,B,C\) have probabilities \(0.10,\ 0.60,\ 0.30\). Which outcomes correspond to inputs \(0.08,\ 0.10,\ 0.69,\ 0.70,\ 0.999\)? (Answer: \(A,B,B,C,C\).)
- Three categories have relative weights \(1,2,1\). Normalize the weights and classify inputs \(0.24,\ 0.25,\ 0.74,\ 0.75\). (Answer: probabilities \(0.25,0.50,0.25\); outcomes \(1,2,2,3\), respectively.)
- A Bernoulli variable has success probability \(0.35\). Classify inputs \(0.349,\ 0.350,\ 0.351\), and state the probability of failure. (Answer: success, failure, failure; \(P(\text{failure})=0.65\).)
- Categories \(L,M,N\) have probabilities \(0.18,\ 0.27,\ 0.55\). Give their intervals and classify inputs \(0.17,\ 0.18,\ 0.44,\ 0.45,\ 0.999\). (Answer: intervals \([0,0.18),[0.18,0.45),[0.45,1)\); outcomes \(L,M,M,N,N\).)