hello,

I'm trying to use Excel VBA to create a function sub for a triangular distribution with parameters a(min), b(mode), and c(max).
The method is:
  • Calculate d = (b-a)/(c-a)
  • Generate a uniformly distributed random number U between 0 and 1 (with the rnd function)
  • If U<d return a+(c-a)*sqr(dU) as the random number
  • Else, return a+(c-a)*[1-sqr((1-d)*(1-U))] as the random number.


Currently I have:

Function Triangular(a As Single, b As Single, c As Single)
    
    Randomize
    Application.Volatile
    
    Dim d As Single
    Dim cumProb As Single
    Dim uniform 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
But it doesn't seem to run on the excel spreadsheet.

Any help is greatly appreciated
Thanks