Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server matrix of standard normal random numbers


MRANDN

Updated: 31 January 2012


Use the scalar function MRANDN to generate an m-by-n matrix of pseudo-random numbers from the standard normal distribution.
Syntax
SELECT [wctMath].[wct].[MRANDN](
  <@m, int,>
 ,<@n, int,>)
Arguments
@m
The number of rows in the matrix.
@n
The number of columns in the matrix.
Return Types
[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.
MRAND
-----------------------------------------------------------------------------
1.26938615493325,-0.510735399848913,0.439030395768966,0.0841593503110295,
2.7457973287989;1.26445818436343,0.0596173318822327,-0.95912653103904,-2.50772017308342,0.585630822523506;-2.67621178753909,1.60866412032457,-0.22329443075971,-
1.91972155706571,0.928475577494124;0.211178680772388,1.16890596780103,
0.0215469248637524,1.09021152404056,-0.268639389277405;-0.130763774333921,0.658344320396729,-1.19580673278149,0.703794007164329,-1.03543177170273
 
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((SELECT wct.MRANDN(5,5)))
This produces the following result.
     RowNum      ColNum              ItemValue
----------- ----------- ----------------------
          0           0      0.486664151521042
          0           1     -0.567230236396191
          0           2      0.484674907807551
          0           3      -1.61395707560988
          0           4     -0.222016957651103
          1           0     -0.423456474077502
          1           1     -0.100743879575708
          1           2      0.387893489904793
          1           3      0.513447522325742
          1           4      0.403226359835378
          2           0     -0.831111263527379
          2           1     -0.172864821084739
          2           2      -1.07306613502404
          2           3      0.951806629501892
          2           4     0.0386401494609591
          3           0       3.03317747854242
          3           1     -0.212743722129218
          3           2       1.27903794817355
          3           3    -0.0910328094225001
          3           4     -0.223731169237102
          4           0       1.08232571163825
          4           1      -0.23794374305386
          4           2      0.753720507632028
          4           3     -0.668095276622906
          4           4       1.11034453149482
 

 



Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service