Skip to content

Instantly share code, notes, and snippets.

@RichPollock
Created February 8, 2013 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichPollock/4738253 to your computer and use it in GitHub Desktop.
Save RichPollock/4738253 to your computer and use it in GitHub Desktop.
Triangular distribution function in VBA. Usage: =TRIDIST(RAND(), 1, 10, 5)
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
@liw311
Copy link

liw311 commented Mar 25, 2018

Very nice. Thank you

@skannan-maf
Copy link

Thanks!

Copy link

ghost commented Jun 10, 2022

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment