ARANDOM

=ARANDOM(a,n)

a
source array
n
integer, nr rows of random array

creates a random array of "n" rows using elements of another array "a"

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ARANDOM creates a random array of "n" rows using elements of another array "a"
Idea credited to Rico, different approach.
Other functions on minisheet ACOMBINE , ADATE , ATEXTJOIN
Excel Formula:
=LAMBDA(a,n,
    LET(c,COLUMNS(a),
       x,INDEX(a,INT(RANDARRAY(n,c)*MMULT(SEQUENCE(,ROWS(a))^0,--(a<>"")))+1,SEQUENCE(,c)),
       IF(x="null","",x)
    )
)
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTUV
11st nameMid nameLst Name2nd Lst NameshufflenDateID-nr_NameProductPackageRegionshuffley
2=ADATE(RANDARRAY(40,,"1-jan-20","30-05-21",1),"f",)
3sample=IF(G1="y",ARANDOM(A4:D23,20),F4#)=ATEXTJOIN(F4#,"ID-"&SEQUENCE(ROWS(F4#))&"_",," ")=IF(R1="y",ARANDOM(K4:O43,45),Q4#)
4MelnullDawkinsMatteiTheodoreKrigerRyburn01-04-20ID-1_Theodore Kriger RyburnQuad3West01-01-21ID-19_Houston Myron Enderle Yanaki18South
5WinfordnullFilerSpethAntioneMyronScheidlerFogle01-04-21ID-2_Antione Myron Scheidler FogleMajestic6South01-06-20ID-8_Rey Myron Mcglothlin MatteiSunset6Canada
6MiguelnullValtierraYaleAntioneGrinnell01-01-21ID-3_Antione Grinnell Yanaki12MidWest01-04-20ID-13_Rey Jamel Dawkins FogleCrested6NorthWest
7HollisnullSheltonLevisonFreddieJereOttenLevison01-07-20ID-4_Freddie Jere Otten LevisonCrested18Canada01-09-20ID-14_Houston Grinnell LevisonGigi12South
8DavisnullPasquarielloFogleMelJereScheidler01-01-20ID-5_Mel Jere Scheidler SunsetMexico01-03-20ID-17_Rudolf Bradly Garth Crested12East
9HoustonnullGrinnellRyburnJesusPasquarielloRyburn01-03-20ID-6_Jesus Pasquariello RyburnGigiNorthWest01-12-20ID-3_Antione Grinnell Yanaki12East
10AntioneJarrodDechantHogeHoustonArnoldoYbarbo01-08-20ID-7_Houston Arnoldo Ybarbo East01-04-21ID-5_Mel Jere Scheidler Gigi3West
11TheodoreRandolphPozonullReyMyronMcglothlinMattei01-12-20ID-8_Rey Myron Mcglothlin Mattei01-04-20ID-8_Rey Myron Mcglothlin MatteiYanaki12East
12VanceArnoldoMcglothlinnullRickyJamelBuskirk01-01-20ID-9_Ricky Jamel Buskirk 01-05-21ID-11_Theodore Grinnell SpethYanaki6Canada
13LindseyHarryBuskirknullMelBradlyBuskirk01-01-20ID-10_Mel Bradly Buskirk 01-01-20ID-13_Rey Jamel Dawkins FogleQuad18MidWest
14RudolfnullOttennullTheodoreGrinnellSpeth01-01-20ID-11_Theodore Grinnell Speth01-12-20ID-13_Rey Jamel Dawkins FogleCrested12South
15RickynullKittermannullAlfredJamelPoulsenMattei01-09-20ID-12_Alfred Jamel Poulsen Mattei01-07-20ID-11_Theodore Grinnell SpethMajestic18South
16JesusJamelGarthReyJamelDawkinsFogle01-05-20ID-13_Rey Jamel Dawkins Fogle01-03-20ID-14_Houston Grinnell LevisonGigi6South
17TomBradlyEnderleHoustonGrinnellLevison01-09-20ID-14_Houston Grinnell Levison01-03-21ID-19_Houston Myron Enderle Yanaki3South
18FreddieMyronPoulsenVanceHarryGarthLevison01-03-20ID-15_Vance Harry Garth Levison01-01-20ID-1_Theodore Kriger RyburnCrested12Canada
19AlvinJereYbarboReyBradlySheltonRyburn01-03-20ID-16_Rey Bradly Shelton Ryburn01-01-20ID-2_Antione Myron Scheidler FogleGigi6South
20AlfonsoSilvestriRudolfBradlyGarth01-02-20ID-17_Rudolf Bradly Garth 01-04-20ID-11_Theodore Grinnell SpethSunset12MidWest
21EduardoScheidlerEduardoJarrodDawkinsFogle01-06-20ID-18_Eduardo Jarrod Dawkins Fogle01-04-20ID-18_Eduardo Jarrod Dawkins FogleSunset6East
22AlfredLuizHoustonMyronEnderle01-01-21ID-19_Houston Myron Enderle 01-04-21ID-8_Rey Myron Mcglothlin MatteiSunset6NorthWest
23ReyKrigerMelJamelValtierraHoge01-05-21ID-20_Mel Jamel Valtierra Hoge01-04-20ID-2_Antione Myron Scheidler FogleSunset3NorthWest
24Note:01-04-2101-03-20ID-3_Antione Grinnell Crested18Mexico
25We can set "null" cells if we want random01-02-2001-03-21ID-6_Jesus Pasquariello RyburnSunset18NorthWest
26created array to contain null strings01-09-2001-03-20ID-13_Rey Jamel Dawkins FogleQuad3East
2701-07-2001-08-20ID-2_Antione Myron Scheidler FogleMajestic18MidWest
28Create a random array01-04-2101-01-20ID-3_Antione Grinnell Majestic12NorthWest
29using this data=ARANDOM(A30:B33,30)Fun quest:01-02-2001-09-20ID-17_Rudolf Bradly Garth Gigi18Mexico
30LGphoneHplaptopDoes the random array01-04-2001-01-20ID-6_Jesus Pasquariello RyburnYanaki3NorthWest
31SamsungcameraHpphonecreated all pos.combinations?01-08-2001-07-20ID-1_Theodore Kriger RyburnYanaki3West
32SonylaptopLGcamera=UNIQUE(D30#)01-03-2101-12-20ID-3_Antione Grinnell Crested6West
33HpSonylaptopHplaptop01-12-2001-07-20ID-6_Jesus Pasquariello RyburnGigi6Mexico
34SamsungphoneHpphone01-12-2001-12-20ID-12_Alfred Jamel Poulsen MatteiQuad18Mexico
35All possibleSamsungphoneLGcamera01-09-2001-01-21ID-14_Houston Grinnell LevisonCrested3South
36combinationsLGlaptopSonylaptop01-03-2101-08-20ID-9_Ricky Jamel Buskirk Majestic12NorthWest
37=ACOMBINE(A30:B33,)LGphoneSamsungphone01-02-2001-01-20ID-7_Houston Arnoldo Ybarbo Yanaki18Mexico
38HpcameraHpcameraLGlaptop01-07-2001-04-21ID-16_Rey Bradly Shelton RyburnYanaki3South
39HplaptopSamsunglaptopLGphone01-01-2001-02-20ID-8_Rey Myron Mcglothlin MatteiQuad6East
40HpphoneSamsungcameraHpcamera01-01-2101-09-20ID-15_Vance Harry Garth LevisonMajestic6NorthWest
41LGcameraSamsungphoneSamsunglaptop01-02-2001-08-20ID-8_Rey Myron Mcglothlin MatteiYanaki12South
42LGlaptopLGphoneSamsungcamera01-01-2001-03-20ID-2_Antione Myron Scheidler FogleMajestic3Mexico
43LGphoneHpcameraSonyphone01-04-2001-01-20ID-13_Rey Jamel Dawkins FogleQuad12Canada
44SamsungcameraLGlaptopSonycamera01-12-20ID-18_Eduardo Jarrod Dawkins FogleQuad6Mexico
45SamsunglaptopSonyphone01-04-21ID-6_Jesus Pasquariello RyburnQuad12West
46SamsungphoneSamsunglaptopIf rows array aboveother functions on minisheet01-03-20ID-13_Rey Jamel Dawkins FogleQuad12West
47SonycameraSamsunglaptopis equal with rows arrayACOMBINE01-12-20ID-20_Mel Jamel Valtierra HogeQuad18Canada
48SonylaptopSonyphoneof all posib.comb then yesADATE01-02-20ID-3_Antione Grinnell Gigi3NorthWest
49SonyphoneLGlaptopotherwise noATEXTJOIN
50Sonycamera
51LGlaptop=IF(ROWS(G33#)=ROWS(A38#),"Yes","No")
52SamsunglaptopAnswer:
53SamsungcameraYes
54Samsunglaptop
55Sonylaptop
56Samsunglaptop
57LGphone
58Sonyphone
59Samsungphone
60
ARANDOM post
Cell Formulas
RangeFormula
K2,G51K2=FORMULATEXT(K4)
F3,A37,G32,D29,Q3,L3F3=FORMULATEXT(F4)
F4:I23F4=IF(G1="y",ARANDOM(A4:D23,20),F4#)
K4:K43K4=ADATE(RANDARRAY(40,,"1-jan-20","30-05-21",1),"f",)
L4:L23L4=ATEXTJOIN(F4#,"ID-"&SEQUENCE(ROWS(F4#))&"_",," ")
Q4:U48Q4=IF(R1="y",ARANDOM(K4:O43,45),Q4#)
D30:E59D30=ARANDOM(A30:B33,30)
G33:H44G33=UNIQUE(D30#)
A38:B49A38=ACOMBINE(A30:B33,)
G53G53=IF(ROWS(G33#)=ROWS(A38#),"Yes","No")
Dynamic array formulas.
 
Upvote 0
Task: Create a random array n rows(50) that should contain, op date, sales person name, product name, product cost, product unit price, region , region discount, units sold, revenue, profit, and print 3 PT reports: tot revenue for product\region ; profit for person\product, all time ; tot revenue monthly\region.
Functions used on minisheet: ADATE , ACLMSPLIT , ARANDOM , APIVOT
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1Task: Create a random table n rows(50) that should contain,op date, sales person name,product, product cost, product unit price, region , region discount, units sold,revenue,profit
2and print 3 PT reports: tot revenue for product\region ; profit for person\product, all time ; tot revenue monthly\region
3Random input data:Random array calculation
4=RANDARRAY(30,,5,15,1)FormulasPT 1 Tot revenue - Product\Region
5=RANDARRAY(50,,"1-05-20","30-05-21",1)=ADATE(ACLMSPLIT(ACLMSPLIT(ARANDOM(A7:E56,50),4,"-"),3,"-"),"m",)=APIVOT(G7:P56,3,6,9,)
6DateNamePrd.,Cost,P/uRegion,DiscUnt.Sld.DateNameProd.CostU.PrcRegionReg.DiscUnt.SoldRevenueProfit(3\6) 9 vf=0EastNorthSouthWestGrand Total
707-08-20Theodore KrigerQuad-7-10West-0.0352021-05-MayAntione ScheidlerYanaki611East6%13134.4256.42Crested263.2107.52186.2258.02814.94
807-07-20Antione ScheidlerMajestic-8-12South-0.0562020-06-JunTheodore KrigerCrested514East6%13171.08106.08Majestic191.76403.2193.8232.81021.56
911-08-20Antione GrinnellYanaki-6-11East-0.06122021-01-JanRey McglothlinMajestic812West3%11128.0440.04Quad244.4240123.5126.1734
1013-02-21Freddie OttenCrested-5-14North-0.0472020-06-JunAntione ScheidlerSunset913South5%9111.1530.15Sunset97.76586.56456.95214.371355.64
1129-11-20Mel ScheidlerSunset-9-1392020-11-NovHouston YbarboMajestic812South5%55717Yanaki237.82496.32365.75330.771430.66
1204-12-20Jesus Pasquariello112021-03-MarFreddie OttenYanaki611West3%885.3637.36Grand Total1034.941833.61326.21162.065356.8
1308-03-21Houston Ybarbo112020-05-MayAntione ScheidlerCrested514South5%679.849.8
1428-06-20Rey Mcglothlin122020-12-DecRey McglothlinQuad710West3%13126.135.1
1514-07-20122020-07-JulAntione GrinnellCrested514South5%8106.466.4PT 2 Profit - Name\Product
1614-05-20132020-12-DecTheodore KrigerYanaki611North4%663.3627.36=APIVOT(G7:P56,2,3,10,)
1718-06-20132021-04-AprAntione GrinnellQuad710South5%13123.532.5(2\3) 10 vf=0CrestedMajesticQuadSunsetYanakiGrand Total
1810-09-20122021-03-MarAntione ScheidlerCrested514North4%8107.5267.52Antione Grinnell66.421.12133.925.76174.71421.89
1909-04-2182020-08-AugFreddie OttenSunset913West3%12151.3243.32Antione Scheidler211.70056.9556.42325.07
2009-01-21112021-04-AprRey McglothlinMajestic812North4%11126.7238.72Freddie Otten57.1229.52061.37123.12271.13
2122-03-21152020-09-SepAntione GrinnellMajestic812North4%669.1221.12Houston Ybarbo052.2024.36076.56
2213-12-20102021-01-JanAntione GrinnellQuad710East6%1514136Jesus Pasquariello00260135.7161.7
2307-05-2082020-11-NovAntione ScheidlerSunset913South5%898.826.8Mel Scheidler026.240048.9575.19
2409-05-2162021-01-JanAntione GrinnellQuad710East6%11103.426.4Rey Mcglothlin68.64106.9235.162.6421.7295
2526-05-21112020-11-NovAntione GrinnellYanaki611North4%10105.645.6Theodore Kriger106.0873.560143.5654.06377.26
2619-05-21102020-08-AugMel ScheidlerMajestic812East6%890.2426.24Grand Total509.94309.56195374.64614.662003.8
2712-10-20122020-10-OctFreddie OttenMajestic812East6%9101.5229.52
2827-05-2082020-07-JulTheodore KrigerMajestic812South5%12136.840.8
2924-08-20132020-08-AugRey McglothlinYanaki611East6%551.721.7PT 3 Tot revenue - month\Region
3019-01-2182020-05-MayHouston YbarboSunset913North4%787.3624.36=APIVOT(G7:P56,1,6,9,)
3118-11-2072021-05-MayFreddie OttenSunset913West3%563.0518.05(1\6) 9 vf=0EastNorthSouthWestGrand Total
3229-03-21152021-03-MarJesus PasquarielloYanaki611North4%995.0441.042020-05-May0202.56178.60381.16
3317-07-2092020-05-MayHouston YbarboMajestic812North4%10115.235.22020-06-Jun171.08149.76278.35160.05759.24
3421-06-2052021-05-MayMel ScheidlerYanaki611South5%11114.9548.952020-07-Jul00243.20243.2
3528-08-2082020-12-DecAntione ScheidlerCrested514West3%11149.3894.382020-08-Aug141.94083.6151.32376.86
3611-05-20112020-06-JunAntione GrinnellYanaki611West3%15160.0570.052020-09-Sep0131.5200131.52
3704-10-202021-03-MarRey McglothlinMajestic812North4%892.1628.162020-10-Oct193.64306.2400499.88
3817-04-212020-10-OctRey McglothlinSunset913North4%13162.2445.242020-11-Nov0105.6155.80261.4
3928-12-202021-05-MayTheodore KrigerMajestic812West3%9104.7632.762020-12-Dec97.76188.160384.12670.04
4027-09-202020-06-JunJesus PasquarielloYanaki611South5%10104.544.52021-01-Jan244.4212.160128.04584.6
4124-05-202020-12-DecTheodore KrigerSunset913North4%10124.834.82021-02-Feb00148.20148.2
4202-04-212020-12-DecRey McglothlinCrested514West3%8108.6468.642021-03-Mar51.7294.72085.36431.78
4319-05-212021-03-MarAntione GrinnellYanaki611East6%551.721.72021-04-Apr0126.72123.50250.22
4411-04-212020-06-JunTheodore KrigerYanaki611South5%662.726.72021-05-May134.42116.16114.95253.17618.7
4523-01-212020-08-AugFreddie OttenYanaki611South5%883.635.6Grand Total1034.941833.61326.21162.065356.8
4603-01-212021-02-FebTheodore KrigerSunset913South5%12148.240.2
4728-07-202020-06-JunTheodore KrigerSunset913North4%12149.7641.76
4821-03-212021-01-JanJesus PasquarielloQuad710North4%109626Other functions on spreadsheet
4928-05-202021-01-JanJesus PasquarielloYanaki611North4%11116.1650.16ADATE
5005-09-202020-12-DecAntione GrinnellSunset913East6%897.7625.76ACLMSPLIT
5112-06-202021-05-MayFreddie OttenYanaki611North4%11116.1650.16ARANDOM
5210-01-212020-09-SepRey McglothlinSunset913North4%562.417.4APIVOT
5318-08-202020-10-OctFreddie OttenCrested514East6%792.1257.12
5406-11-202020-10-OctAntione GrinnellQuad710North4%1514439
5530-05-202021-05-MayAntione GrinnellYanaki611West3%885.3637.36
5628-10-202020-05-MayTheodore KrigerSunset913South5%898.826.8
57
58Note: Is important to have data in this format when there are unique relations (like product, cost price, selling price or region, region discount) before "randomize" it, for consistency.
59Only after randomize it, splitting it with ACLMSPLIT(nested if we need more clms to split), will guarantee that data is kept consistent.
60That is the main reason is no need to write a separate function for randomizing values, plus, to create real life alike random data sets, is better to add columns that do calculations, and not inert data that has no meaning.
61
ARANDOM example
Cell Formulas
RangeFormula
C4C4=FORMULATEXT(E7)
A5,G5A5=FORMULATEXT(A7)
S5,S30,S16S5=FORMULATEXT(S6)
S6:X12S6=APIVOT(G7:P56,3,6,9,)
A7:A56A7=RANDARRAY(50,,"1-05-20","30-05-21",1)
E7:E36E7=RANDARRAY(30,,5,15,1)
G7:N56G7=ADATE(ACLMSPLIT(ACLMSPLIT(ARANDOM(A7:E56,50),4,"-"),3,"-"),"m",)
O7:O56O7=K7:K56*N7:N56*(1-M7:M56)
P7:P56P7=O7#-(J7:J56*N7:N56)
S17:Y26S17=APIVOT(G7:P56,2,3,10,)
S31:X45S31=APIVOT(G7:P56,1,6,9,)
Dynamic array formulas.
 

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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