Logo

RANDSNORMAL

Updated 2023-10-18 19:33:29.050000

Syntax

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

Description

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

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

{"columns": [{"field": "colName", "headerName": "Name", "header": "name"}, {"field": "colDatatype", "headerName": "Type", "header": "type"}, {"field": "colDesc", "headerName": "Description", "header": "description", "minWidth": 1000}], "rows": [{"id": "4a32fc76-d93f-4cca-8c24-6aa57953a459", "colName": "Seq", "colDatatype": "int", "colDesc": "A monotonically increasing sequence number"}, {"id": "bd394282-ab93-464d-89c2-ea7924d9b4cd", "colName": "X", "colDatatype": "float", "colDesc": "The 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:

{"columns":[{"field":"X","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"COUNT","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"X":"-4","COUNT":"31"},{"X":"-3","COUNT":"1318"},{"X":"-2","COUNT":"21400"},{"X":"-1","COUNT":"135905"},{"X":"0","COUNT":"682689"},{"X":"1","COUNT":"135905"},{"X":"2","COUNT":"21400"},{"X":"3","COUNT":"1318"},{"X":"4","COUNT":"31"}]}
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.

{"columns":[{"field":"X","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"COUNT","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"X":"-4","COUNT":"32"},{"X":"-3","COUNT":"1340"},{"X":"-2","COUNT":"21481"},{"X":"-1","COUNT":"135744"},{"X":"0","COUNT":"682726"},{"X":"1","COUNT":"136048"},{"X":"2","COUNT":"21333"},{"X":"3","COUNT":"1278"},{"X":"4","COUNT":"18"}]}

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 (?).