RANDDATA

=RANDDATA(data,noOfRows,incValueColumn,minValue,maxValue,noOfDecimals)

data
2D array of data containing columns of fields and values
noOfRows
number of rows of random data to be generated
incValueColumn
add a value column to the random data
minValue
minimum value in the value column
maxValue
maximum value in the value column
noOfDecimals
number of decimal places in the value column

RANDDATA Creates a 2D array (of n rows) of random data from a 2D array of fields/dimension data.

RicoS

Board Regular
Joined
May 1, 2019
Messages
62
RANDDATA Creates a 2D array (of n rows) of random data from a 2D array of fields/dimension data.

SORTROWS Lambda Function is used in this function.

Excel Formula:
=LAMBDA(data,noOfRows,incValueColumn,minValue,maxValue,noOfDecimals,
   LET(d,data,nOR,noOfRows,
      c,COLUMNS(d),r,ROWS(d),
      sC,SEQUENCE(,c+incValueColumn),sR,SEQUENCE(r),
      mxRows,INDEX(SORTROWS(TRANSPOSE(ISBLANK(d)*(sR-1)),1),,1),
      lastRow,TRANSPOSE(IF(mxRows=0,r,mxRows)),
      sNR,SEQUENCE(nOR+1,c),rw,INT(sNR/(c+1)),sNR_1,SEQUENCE(nOR+1),
      firstRows,2-(rw=0),
      lastRows,IF(rw=0,1,(rw*0)+lastRow),
      randArr,IF(incValueColumn,ROUND(RANDARRAY(nOR,1,minValue,maxValue,FALSE),noOfDecimals)),
      amountColumn,IF(incValueColumn,IF(sNR_1=1,"Amount",INDEX(randArr,sNR_1-1))),
      dataRow,IF(sC=c+1,amountColumn,INDEX(d,RANDBETWEEN(firstRows,lastRows),sC)),
   dataRow)
)

Book1
ABCDEFGHIJKL
1CountryAreaMonthPersonCurrencyCountryAreaMonthPersonCurrencyAmounts
2ScotlandNorthJanAndyGBPItalySouthDecBarryUSD1495
3EnglandEastFebDaveUSDWalesWestMarKarenGBP1139
4WalesSouthMarMichelleWalesEastSepAndyGBP654
5IrelandWestAprEsmeWalesWestMayEsmeUSD1203
6FranceMayBarryItalySouthAugEsmeUSD914
7ItalyJunKarenScotlandEastJunBarryUSD1192
8JulWalesSouthSepKarenUSD842
9AugScotlandWestJulMichelleGBP811
10SepFranceSouthAprAndyUSD457
11OctEnglandWestAugBarryUSD1495
12NovIrelandWestAugDaveUSD278
13DecIrelandNorthAprAndyUSD625
14EnglandNorthMayKarenGBP1030
15ItalyWestSepKarenUSD458
16ScotlandWestAprBarryGBP715
17EnglandSouthFebMichelleGBP945
18IrelandWestJunAndyGBP1216
19EnglandNorthJulAndyGBP446
20EnglandNorthOctAndyGBP443
21FranceSouthFebMichelleGBP1339
Data
Cell Formulas
RangeFormula
G1:L21G1=RANDDATA(A1:E13,20,1,200,1500,0)
Dynamic array formulas.
 
Last edited by a moderator:
Upvote 0
The idea to create rand data is super cool !! Kudos for that !! ?✌
Did not understand, what sortrows function (that calls other 3 dif lambdas) does here?
To calculate the "depth" (height) of each column of "data" array?
For that you can use only MMULT(SEQUENCE(,ROWS(data))^0,--(data<>"")) You will get (including headers row) : 7,13,7,3 (let's call it mr)
Then a simple INT(RANDARRAY(nofrows,COLUMNS(data))*mr)+1 will create the array of random row indexes
This is how it looks, a lambda that addresses the core of this concept (adding headers or values column is simple array cosmetics, no problems there, although I think we need more columns with values in a real life alike data set, not only 1, like real dates , unit prices, %discounts, costs, units sold, totals..etc )
ARANDDATA(a,n) a: "data" array ; n: nr. rows to be generated
Excel Formula:
=LAMBDA(a,n,LET(c,COLUMNS(a),INDEX(a,INT(RANDARRAY(n,c)*MMULT(SEQUENCE(,ROWS(a))^0,--(a<>"")))+1,SEQUENCE(,c))))
Book1
ABCDEFGHIJKL
1=ARANDDATA(A2:E13,20)
2ScotlandNorthJanAndyGBPEnglandEastJunAndyGBP
3EnglandEastFebDaveUSDEnglandNorthAprAndyGBP
4WalesSouthMarMichelleEnglandNorthJulDaveGBP
5IrelandWestAprEsmeEnglandNorthJanAndyUSD
6FranceMayBarryFranceEastMayAndyUSD
7ItalyJunKarenIrelandNorthJanDaveUSD
8JulIrelandNorthJanDaveGBP
9AugFranceNorthJanDaveGBP
10SepFranceSouthAugAndyUSD
11OctWalesWestSepKarenUSD
12NovFranceEastMayEsmeUSD
13DecItalySouthAugBarryUSD
14WalesWestAugMichelleUSD
15EnglandNorthSepBarryGBP
16ScotlandNorthMayMichelleGBP
17WalesNorthJanDaveGBP
18ItalySouthFebBarryUSD
19WalesWestSepAndyUSD
20EnglandNorthSepKarenGBP
21ItalyEastOctEsmeGBP
22
Sheet3
Cell Formulas
RangeFormula
G1G1=FORMULATEXT(G2)
G2:K21G2=ARANDDATA(A2:E13,20)
Dynamic array formulas.
 
Last edited:

Forum statistics

Threads
1,223,604
Messages
6,173,316
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top