generateCauchy(x0, gamma)
Overview
The generateCauchy(x0, gamma)
function generates a random number that follows a Cauchy distribution.
Parameters
Parameter | Type | Description |
---|---|---|
x0 |
Number | The location parameter of the Cauchy distribution. |
gamma |
Number | The scale parameter of the Cauchy distribution. |
Returns
Return | Type | Description |
---|---|---|
result |
Number | A random number from a Cauchy distribution. |
Example
local result = StatBook.generateCauchy(0, 1)
print(result) -- Output will vary
Mathematical Background
The function generates a random number result that follows a Cauchy distribution with location parameter x0 and scale parameter γ.
The probability density function (pdf) of the Cauchy distribution is defined as:
f(x;x0,γ)=1πγ[1+(x−x0γ)2]
In this implementation, the random variable from the Cauchy distribution is generated using the formula:
result=x0+γtan(π(U−0.5))
where U is a uniformly distributed random number between 0 and 1.