Logo

MRANDN

Updated 2023-10-20 15:03:47.133000

Syntax

SELECT [westclintech].[wct].[MRANDN](
  <@m, int,>
 ,<@n, int,>)

Description

Use the scalar function MRANDN to generate an m-by-n matrix of pseudo-random numbers from the standard normal distribution.

Arguments

@m

The number of rows in the matrix.

@n

The number of columns in the matrix.

Return Type

nvarchar(max)

Remarks

@m must be greater than or equal to 1.

@n must be greater than or equal to 1.

Examples

The following statement will produce the 5-by-5 matrix of pseudo-random numbers from the standard normal distribution.

SELECT wct.MRANDN(5, 5) as MRANDN;

This produces the following result.

{"columns":[{"field":"MRANDN"}],"rows":[{"MRANDN":"0.409996709727112,-0.00447533995227935,-0.569381336855175,-0.444344964509572,-0.392413392483098;0.447740037998686,1.82518912506013,1.97445852461499,1.11767069519037,-0.548575208347825;-1.00418675832274,0.243530252013792,-0.632482682458317,1.47321822469948,0.196537106300479;0.403285434343591,1.69772959633896,0.153027620710726,0.74438203750852,1.56098232233076;0.533510355172554,0.0764553206281185,-1.65467638890231,0.111361220136488,-1.1633185022047"}]}

Since this is a matrix of random numbers, your results will be different.

We can use the table-valued function MATRIX to produce the output in third-normal form.

SELECT *
FROM wct.MATRIX(wct.MRANDN(5,5));

This produces the following result.

{"columns":[{"field":"RowNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ColNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ItemValue","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"RowNum":"0","ColNum":"0","ItemValue":"-0.182917665796923"},{"RowNum":"0","ColNum":"1","ItemValue":"-0.307999198184022"},{"RowNum":"0","ColNum":"2","ItemValue":"-0.307359629916836"},{"RowNum":"0","ColNum":"3","ItemValue":"0.680657933114575"},{"RowNum":"0","ColNum":"4","ItemValue":"0.524831239703179"},{"RowNum":"1","ColNum":"0","ItemValue":"-0.853272587740419"},{"RowNum":"1","ColNum":"1","ItemValue":"-0.416493322946868"},{"RowNum":"1","ColNum":"2","ItemValue":"-1.16459866817653"},{"RowNum":"1","ColNum":"3","ItemValue":"-1.2475033746981"},{"RowNum":"1","ColNum":"4","ItemValue":"-2.20881434337242"},{"RowNum":"2","ColNum":"0","ItemValue":"1.05329158720774"},{"RowNum":"2","ColNum":"1","ItemValue":"0.866228021008215"},{"RowNum":"2","ColNum":"2","ItemValue":"0.245181973863511"},{"RowNum":"2","ColNum":"3","ItemValue":"-0.115983115116491"},{"RowNum":"2","ColNum":"4","ItemValue":"-0.0635604193448651"},{"RowNum":"3","ColNum":"0","ItemValue":"1.16601372633918"},{"RowNum":"3","ColNum":"1","ItemValue":"1.97154575890409"},{"RowNum":"3","ColNum":"2","ItemValue":"-0.591647363421029"},{"RowNum":"3","ColNum":"3","ItemValue":"-0.81158959859554"},{"RowNum":"3","ColNum":"4","ItemValue":"0.309715756989705"},{"RowNum":"4","ColNum":"0","ItemValue":"0.565948667517376"},{"RowNum":"4","ColNum":"1","ItemValue":"0.571141049105415"},{"RowNum":"4","ColNum":"2","ItemValue":"-2.11372801052463"},{"RowNum":"4","ColNum":"3","ItemValue":"-1.59100488073806"},{"RowNum":"4","ColNum":"4","ItemValue":"0.541094492166664"}]}