Logo

MRAND

Updated 2023-10-20 15:01:52.987000

Syntax

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

Description

Use the scalar function MRAND to generate an m-by-n matrix of pseudo-random numbers greater than or equal to zero and less than one.

Arguments

@m

The number of rows in the random number matrix.

@n

The number of columns in the random number 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 random numbers.

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

This produces the following result.

{"columns":[{"field":"MRAND"}],"rows":[{"MRAND":"0.771425607507781,0.134477493415809,0.10550751309167,0.84613314543205,0.798585127479669;0.62770994223082,0.333486620026402,0.80377489691776,0.916069948075372,0.872625331335061;0.380903457468796,0.921585860159987,0.12491698289519,0.343612862910895,0.240248040873673;0.345327849195026,0.946873843645153,0.340558091337121,0.684887842128467,0.50751098594978;0.751433997299259,0.288153123244715,0.41803163682019,0.574196451610977,0.140616484517519"}]}

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.MRAND(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.0917199370878376"},{"RowNum":"0","ColNum":"1","ItemValue":"0.412955388153417"},{"RowNum":"0","ColNum":"2","ItemValue":"0.483272484263066"},{"RowNum":"0","ColNum":"3","ItemValue":"0.71644585659562"},{"RowNum":"0","ColNum":"4","ItemValue":"0.531311061480693"},{"RowNum":"1","ColNum":"0","ItemValue":"0.705516660914531"},{"RowNum":"1","ColNum":"1","ItemValue":"0.765202311223933"},{"RowNum":"1","ColNum":"2","ItemValue":"0.511808382119894"},{"RowNum":"1","ColNum":"3","ItemValue":"0.138445003022647"},{"RowNum":"1","ColNum":"4","ItemValue":"0.135214033599577"},{"RowNum":"2","ColNum":"0","ItemValue":"0.94421862947951"},{"RowNum":"2","ColNum":"1","ItemValue":"0.126662550553057"},{"RowNum":"2","ColNum":"2","ItemValue":"0.44067387722464"},{"RowNum":"2","ColNum":"3","ItemValue":"0.854030737585402"},{"RowNum":"2","ColNum":"4","ItemValue":"0.84381542626946"},{"RowNum":"3","ColNum":"0","ItemValue":"0.56869187698173"},{"RowNum":"3","ColNum":"1","ItemValue":"0.366157882551736"},{"RowNum":"3","ColNum":"2","ItemValue":"0.217814114046196"},{"RowNum":"3","ColNum":"3","ItemValue":"0.977821422264828"},{"RowNum":"3","ColNum":"4","ItemValue":"0.645701881333115"},{"RowNum":"4","ColNum":"0","ItemValue":"0.595174356175202"},{"RowNum":"4","ColNum":"1","ItemValue":"0.712435110803896"},{"RowNum":"4","ColNum":"2","ItemValue":"0.660999368252698"},{"RowNum":"4","ColNum":"3","ItemValue":"0.783122740584948"},{"RowNum":"4","ColNum":"4","ItemValue":"0.519691777657574"}]}