sbRandCDFInv

You can create random numbers with a given distribution easily if you have an explicit form of the inverse of the cumulative distribution function:

Please read my Disclaimer.

Function sbRandCDFInv(dParam1 As Double, dParam2 As Double, _
    dParam3 As Double, Optional dRandom = 1#) As Double
'Source: https://berndplumhoff.gitbook.io/sulprobil/excel/excel-vba-solutions/sbrandcdfinv
'03-Nov-2020 PB V0.2
Static bRandomized As Boolean
Dim dRand As Double
If dRandom < 0# Or dRandom > 1# Then
    sbRandCDFInv = CVErr(xlErrValue)
    Exit Function
End If
If Not bRandomized Then
    Randomize
    bRandomized = True
End If
If dRandom = 1# Then
    dRand = Rnd()
Else
    dRand = dRandom
End If
'Here you need to define the inverse of the cumulative distribution function
sbRandCDFInv = sbRandTriang(dParam1, dParam2, dParam3, dRand)
End Function

This function will provide with a stratified sample:

Other examples would be sbRandCauchy or sbRandTriang directly.

If there is no explicit form of a cumulative distribution function inverse then you can apply a linear approximation with the probability distribution function sbRandPDF.

Last updated