Alias method: Difference between revisions

116 bytes added ,  4 years ago
Undid revision 711324558 by Jiamings (talk): the variable y is computed from x in step 2, it does not need to be generated separately
m (Add variable y which is missing)
(Undid revision 711324558 by Jiamings (talk): the variable y is computed from x in step 2, it does not need to be generated separately)
More concretely, the algorithm operates as follows:
 
# Generate twoa [[Uniform distribution (continuous)|uniform]] random variablesvariate {{math|0 ≤ ''x'' < 1}} and {{math|0 ≤ ''y'' < 1}}.
# Let {{math|1=''i'' = ⌊''nx''⌋ + 1}} and {{math|1=''y'' = ''nx'' + 1 − ''i''}}. (This makes {{math|''i''}} uniformly distributed on {{math|{1, 2, …, ''n''} }} and {{math|''y''}} uniformly distributed on {{math|[0, 1)}}.)
# If {{math|''y'' &lt; ''U<sub>i</sub>''}}, return {{mvar|i}}. This is the biased coin flip.
# Otherwise, return {{mvar|K<sub>i</sub>}}.