Logo

SQL Server MRANDN Function

Updated 2023-10-20 15:03:47.133000

Description

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

Syntax

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

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.

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.

RowNumColNumItemValue
00-0.182917665796923
01-0.307999198184022
02-0.307359629916836
030.680657933114575
040.524831239703179
10-0.853272587740419
11-0.416493322946868
12-1.16459866817653
13-1.2475033746981
14-2.20881434337242
201.05329158720774
210.866228021008215
220.245181973863511
23-0.115983115116491
24-0.0635604193448651
301.16601372633918
311.97154575890409
32-0.591647363421029
33-0.81158959859554
340.309715756989705
400.565948667517376
410.571141049105415
42-2.11372801052463
43-1.59100488073806
440.541094492166664