Logo

SQL Server RANDCAUCHY Function

Updated 2023-10-18 15:36:31.553000

Description

Use the table-valued function RANDCAUCHY to generate a sequence of random numbers from a Cauchy distribution with locations @mu and scale @sig.

Syntax

SELECT * FROM [westclintech].[wct].[RANDCAUCHY](
  <@Rows, int,>
 ,<@mu, float,>
 ,<@sig, float,>)

Arguments

@Rows

the number of rows to generate. @Rows must be of the type int or of a type that implicitly converts to int.

@mu

the location parameter. @mu must be of the type float or of a type that implicitly converts to float.

@sig

the scale parameter. @sig must be of the type float or of a type that implicitly converts to float.

Return Type

table

colNamecolDatatypecolDesc
SeqintA monotonically increasing sequence number
XfloatThe random variable

Remarks

@sig must be greater than zero.

If @mu is NULL then @mu is set to 0.

If @sig is NULL then @sig is set to 1.

If @Rows is less than 1 then no rows are returned.

Examples

In this example we create a sequence 1,000,000 random numbers rounded to one decimal place from a Cauchy distribution with @mu = 0 and @sig = 1, COUNT the results, paste them into Excel where the values are between -10 and 10 and graph them.

SELECT X,
       COUNT(*) as COUNT
FROM
(
    SELECT ROUND(X, 1) as X
    FROM wct.RANDCAUCHY(   1000000, --@Rows
                           0,       --@mu
                           1        --@sig
                       )
) n
WHERE X
BETWEEN -10 AND 10
GROUP BY X
ORDER BY 1;

This produces the following result.

http://westclintech.com/Portals/0/images/doc_math_RANDCAUCHY_img1.jpg

See Also

CAUCHYINV - Calculate the inverse lower cumulative distribution of the Cauchy distribution.

RANDBETA - Random numbers from a beta distribution

RANDBINOM - Random numbers from a binomial distribution

RANDCHISQ - Random numbers from a chi-squared distribution

RANDEXP - Random numbers from an exponential distribution

RANDFDIST - Random numbers from an F-distribution

RANDGAMMA - Random numbers from a gamma distribution

RANDLAPLACE - Random numbers from a LaPlace distribution

RANDLOGISTIC - Random numbers from a logistic distribution

RANDNORMAL - Random numbers from the normal distribution

RANDPOISSON - Random numbers from a Poisson distribution

RANDSNORMAL - Random numbers from the standard normal distribution

RANDTDIST - Random numbers from Student's t distribution

RANDWEIBULL - Generate a sequence of random numbers from w Weibull distribution with parameters shape (?) and scale (?).