Sulprobil
Search…
sbRandCauchy
If you like to simulate how particles emanating from a fixed point hit a straight line you can use a Cauchy distribution. This distribution is sometimes called a Lorentz distribution, too. The quotient of two Normal(0,1) distributions also leads to a Cauchy distribution.
Stratified samples of 10,000 runs
Please read my Disclaimer.
1
Const GCPi = 3.14159265358979
2
3
Function sbRandCauchy(dLocation As Double, dScale As Double, _
4
Optional dRandom = 1#) As Double
5
'Source: https://berndplumhoff.gitbook.io/sulprobil/excel/excel-vba-solutions/sbrandcauchy
6
'03-Nov-2020 PB V.02
7
Static bRandomized As Boolean
8
Dim dRand As Double
9
If dRandom < 0# Or dRandom > 1# Or dScale <= 0# Then
10
sbRandCauchy = CVErr(xlErrValue)
11
Exit Function
12
End If
13
If Not bRandomized Then
14
Randomize
15
bRandomized = True
16
End If
17
If dRandom = 1# Then
18
dRand = Rnd()
19
Else
20
dRand = dRandom
21
End If
22
sbRandCauchy = dLocation + dScale * Tan((dRand - 0.5) * GCPi)
23
End Function
Copied!
Last modified 1yr ago
Copy link