objective c - Calculating value based on weighted percentage chance -
i writing program in need random value based on weighted chances , having real difficulty. example of need do:
a = 50%, b = 30%, c = 10%, d = 10%
in example, need able random value, a,b,c or d, value coming being 'a' 50% of time, b 30% of time, etc...
many thanks
assign each value range of numbers between 0 , 1 based on chance should appear. example, should 0 .5, since needs 50% chance. then, random number between 0 , 1. whichever value's range random number falls value get.
a = [0, .5)
b = [.5, .8)
c = [.8, .9)
d = [.9, 1)
random number [0,1)
[ = inclusive, ) = exclusive.
Comments
Post a Comment