Logo

SQL Server RANDSNORMAL Function

Updated 2023-10-18 19:33:29.050000

Description

Use the table-valued function RANDSNORMAL to generate a sequence of random numbers from the standard normal distribution.

Syntax

SELECT * FROM [westclintech].[wct].[RANDSNORMAL](
   <@Rows, int,>)

Arguments

@Rows

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

Return Type

table

colNamecolDatatypecolDesc
SeqintA monotonically increasing sequence number
XfloatThe random variable

Remarks

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

Examples

In this example we create a sequence 1,000,000 truncated random numbers from the standard normal distribution and COUNT the results. Elementary statistics leads us to expect the results to be distributed approximately like this:

XCOUNT
-431
-31318
-221400
-1135905
0682689
1135905
221400
31318
431
SELECT X,
       COUNT(*) as [COUNT]
FROM
(SELECT wct.TRUNC(x, 0) as x FROM wct.RANDSNORMAL(1000000) ) n
GROUP BY X
ORDER BY 1;

This produces the following result. Your results will be different.

XCOUNT
-432
-31340
-221481
-1135744
0682726
1136048
221333
31278
418

See Also

NORMINV - Inverse of the normal distribution

NORMSINV - Inverse of the standard normal distribution

RANDBETA - Random numbers from a beta distribution

RANDBINOM - Random numbers from a binomial distribution

RANDCAUCHY - Random numbers from a Cauchy 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

RANDTDIST - Random numbers from Student's t distribution

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