-2

I need help creating a general function or pseudocode that chooses a single event from a group events who all have different probabilities. Ex.

  • event 1 = 45%
  • event 2 = 15%
  • event 3 = 50%
  • event 4 = 35%
  • event 5 = 50%
O.J.
  • 133
  • 6
  • What does the C++ tag stand for? – skypjack Dec 28 '15 at 23:08
  • I will be coding in c++ – O.J. Dec 28 '15 at 23:08
  • 3
    Possible duplicate of [C++ function for picking from a list where each element has a distinct probability](http://stackoverflow.com/questions/2649717/c-function-for-picking-from-a-list-where-each-element-has-a-distinct-probabili) – matt. Dec 29 '15 at 00:36

1 Answers1

0

The simplest solution would be to sum and normalize the ranges (as an example, the sum of the values is 195, your first event would get the range [0, 45/195=0.23[, the second one [0.23, 0.23+0.076=0.31], and so on), then extract a number from [0,1[ and look to what range it belongs.

skypjack
  • 49,335
  • 19
  • 95
  • 187