math - Probability Realization -


if have probabilities of x, y, , z events occurring, how can programatically realize choosing between these 3 events?

example: pr(x) = 0.3 pr(y) = 0.2 pr(z) = 0.5

i'd function give me realization of these probabilities should choose y, or maybe z, etc.

any pointers or references appreciated, thanks.

if have function rand() returns uniform random number in [0,1], then

float r = rand(); if (rand < pr(x)) {     return x; } else if (rand < pr(x)+pr(y)) {     return y; } else {     return z; } 

similarly, if can generate random integer between, say, 1 , 100,

int r = rand(); if (rand < pr(x)*100) {     return x; } else if (rand < (pr(x)+pr(y))*100) {     return y; } else {     return z; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -