cumProb = Prob(1):
1. Prob does not correspond to syntax and description of the Worksheetfunction per Microsoft.:PROB(x_range,prob_range,lower_limit,upper_limit)
2. CumProb is never used in the function.
Option Explicit
Function Triangular(a As Single, b As Single, c As Single) As Double
Randomize
Application.Volatile
Dim d As Single
Dim cumProb As Single
Dim uniform As Single
Dim RetVal As Single
d = (b - a) / (c - a)
uniform = Rnd()
'cumProb = Prob(1)
If uniform < d Then
Triangular = a + (c - a) * Sqr(d * uniform)
Else
Triangular = a + (c - a) * (1 - Sqr(1 - d) * (1 - uniform))
End If
End Function
Sub caller()
Debug.Print Triangular(3, 4, 6) ======> returns 5.47996471111746
End Sub
Bookmarks