Simple probability question with javascript

49 Views Asked by At

Some function outputs +0, +1, +2 or +3 The probability of getting:

+0 : 31%

+1 : 40%,

+2 : 20%,

+3 : 9%

Totaling 100%

What is the average decimal/float +X from this function? For example if all of them were 25% then the average +X would be 1.50.

Came up with the following but I'm not sure it's correct: ((plus0*0) + (plus1*1) + (plus2*2) + (plus3*3)) / 100 = X