Discussion:
How to deal with variable probabilities?
(too old to reply)
mpalmer
2017-11-22 07:44:39 UTC
Permalink
Raw Message
In a lot of projects I'm dealing with outcomes of variable probabilities. Say
A = .3
B = .1
C = .6
Up to now I set up a 100-size array and distribute the values 1-30 = A, 31-40 = B, and 41-100 = C, and then use a random generator to tell me which value should be selected. Is there an easier/more efficient way to do this?
dpb
2017-11-22 19:24:06 UTC
Permalink
Raw Message
Post by mpalmer
In a lot of projects I'm dealing with outcomes of variable probabilities. Say
A = .3
B = .1
C = .6
Up to now I set up a 100-size array and distribute the values 1-30 =
A, 31-40 = B, and 41-100 = C, and then use a random generator to tell
me which value should be selected. Is there an easier/more efficient
way to do this?
You don't need the ancillary array; simply test against the breakpoints...

It's not totally clear just how this fits into the model; a little
context would likely elicit more explicit coding solution(s).

--
mpalmer
2017-11-24 19:18:10 UTC
Permalink
Raw Message
Ok, I think I see what you mean about not using an array.

For an example, I'm thinking of something like character probabilities in a text. So in a 100-character text, A appears 10x, B 3X, C 1X, etc. I want to generate a random text using these probabilities as a basis.
Loading...