Created
February 8, 2013 11:20
-
-
Save RichPollock/4738253 to your computer and use it in GitHub Desktop.
Triangular distribution function in VBA. Usage: =TRIDIST(RAND(), 1, 10, 5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function TRIDIST(random As Double, min As Double, max As Double, mode As Double) | |
If mode < min Or max < mode Then | |
TRIDIST = CVErr(xlErrValue) | |
Else | |
If random <= (mode - min) / (max - min) Then | |
TRIDIST = min + Sqr((max - min) * (mode - min) * random) | |
Else | |
TRIDIST = max - Sqr((max - min) * (max - mode) * (1 - random)) | |
End If | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!