Random generate multiple names from a list with exclusions & sorting

camspy

New Member
Joined
Jan 7, 2022
Messages
43
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Here's my table:

Screenshot_1.png


Here's also the sheet:

test.xlsx
ABCDEF
1NamesRankExcludesimplesortedsorted+excluded
2Abigail65Olivia
3Sophia25Mila
4Amelia30
5Elizabeth80Isabella,Sophia,Amelia
6Ava15Gianna,Emma
7Isabella35Luna
8Gianna60
9Harper50
10Mila100Sofia
11Olivia5
12Charlotte20
13Evelyn45Camila,Ava,Abigail
14Avery95Charlotte
15Emily90Evelyn,Mia
16Ella75
17Sofia85Avery,Emily
18Mia40Elizabeth,Ella
19Camila55
20Emma10Harper
21Luna70
Sheet1


I need to generate 10 random names (delimited), without duplicates, in each cell of columns D, E and F, the rules are below:
  1. In column D: just the list of 10 randomly generated and delimited names, without dupes;
  2. In column E: the same as in column D, but the results should be sorted by ranks taken from B2:B21, from high to low;
  3. In column F: the same as in column E, but the results will have per-row exclusions, listed in column C.

Each result should contain 10 names, and visually should look like this: Sophia,Amelia,Isabella,Mia,Evelyn,Harper,Camila,Gianna,Abigail,Luna

I have tried many of the solutions with RANDARRAY and RANDBETWEEN formulas found on the internet, but didn't succeed myself.

Maybe it's not even possible to have it working using just formulas?
Maybe VBA is required?

Any help is appreciated.
Thanks in advance.
 
Ok, did some testing, put the col F formula into cells D24:BA24 & counted how many times each name occurred & ran the calculation 22 times & these are the results.
+Fluff 1.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXY
24AveryAbigailElizabethMilaMilaAveryMilaMilaAveryEmilyEmilyAveryEmilyAveryAveryMilaAveryEmilyMilaMilaEmilyMila
25EmilyGiannaEllaSofiaEmilyEllaEmilySofiaEllaSofiaSofiaEmilySofiaEllaSofiaEmilySofiaSofiaAveryElizabethSofiaSofia
26SofiaHarperGiannaLunaSofiaLunaEllaElizabethAbigailEllaAbigailSofiaEllaLunaEllaGiannaLunaElizabethSofiaEllaElizabethElla
27EllaEvelynMiaHarperElizabethAbigailAbigailLunaCamilaLunaGiannaCamilaLunaAbigailLunaCamilaAbigailAbigailElizabethAbigailAbigailCamila
28AbigailIsabellaIsabellaMiaGiannaGiannaGiannaGiannaEvelynCamilaHarperHarperAbigailGiannaAbigailEvelynHarperCamilaAbigailEvelynCamilaHarper
29GiannaAmeliaAmeliaIsabellaCamilaCamilaCamilaIsabellaAmeliaEvelynEvelynMiaHarperEvelynGiannaMiaEvelynAmeliaCamilaIsabellaIsabellaEvelyn
30CamilaCharlotteSophiaSophiaEvelynEvelynIsabellaAmeliaSophiaMiaMiaSophiaIsabellaAmeliaCharlotteIsabellaMiaCharlotteIsabellaAmeliaCharlotteAmelia
31MiaAvaCharlotteCharlotteIsabellaIsabellaSophiaSophiaCharlotteIsabellaSophiaCharlotteSophiaSophiaAvaCharlotteIsabellaAvaCharlotteCharlotteAvaCharlotte
32AmeliaEmmaAvaEmmaAmeliaSophiaEmmaEmmaEmmaAmeliaAvaEmmaCharlotteAvaEmmaEmmaAmeliaEmmaAvaAvaEmmaEmma
33EmmaOliviaEmmaOliviaCharlotteCharlotteOliviaOliviaOliviaEmmaEmmaOliviaAvaOliviaOliviaOliviaCharlotteOliviaOliviaEmmaOliviaOlivia
34
35Abigail311100011010101110111110
36Sophia200011011110111100000000
37Amelia271110100111000100110101
38Elizabeth240010100100000000011110
39Ava260110000000101110011110
40Isabella290111111101001001101110
41Gianna261110111100100111000000
42Harper200101000000111000100001
43Mila210001101100000001001101
44Olivia260101001110010111011011
45Charlotte330111110010011011111111
46Evelyn200100110011100101100101
47Avery191000010010010110101000
48Emily231000101001111001010010
49Ella251010011011001110000101
50Sofia321001100101111010111011
51Mia191011000001110001100000
52Camila261000111011010001011011
53Emma321111001111110011010111
54Luna210001010101001110100000
55
56Abigail2825282126251725292725252526262423272421222024.5023.68
57Sophia2828242924242524282322212623222325222426222724.5526.36
58Amelia1425282824232820312325222723242930212824242624.86
59Elizabeth2525242224212529212722272524282525302228262725.0914
60Ava2522182623232325301927252229312322322126312624.9540
61Isabella2424222822262820222024322331233028272621252725.14
62Gianna2328372418243131292720222226262333192722222425.36
63Harper1723262321262129263030262619192227292529302524.95
64Mila2829212728252015223226273423292127273024262125.55
65Olivia2919253224252720202626232927212426192230232324.55
66Charlotte2423282622282726212426282323233128292724242925.64
67Evelyn2525212427273026172827292423232630262524222125.00
68Avery2925242425232127182722182820292423232529302424.45
69Emily2624282527232828222424262623242423281831262325.05
70Ella2527232327241918272626262426252515262421182623.68
71Sofia2926253028252934242429302125273022192628252426.36
72Mia2623232028252428293132243040212428212817222826.00
73Camila2429222225212526252118251923262418242524272923.73
74Emma2229232627372823312322222225262824292827322526.32
75Luna2921302030252426281827222421272023222524232524.27
Main
Cell Formulas
RangeFormula
D24:Y33D24=LET(Ex,FILTERXML("<k><m>"&SUBSTITUTE(C2,",","</m><m>")&"</m></k>","//m"),f,FILTER($A$2:$B$21,ISNA(MATCH($A$2:$A$21,IF(COUNTA(Ex)=1,C2,Ex),0))),INDEX(SORT(INDEX(SORTBY(f,RANDARRAY(ROWS(f))),SEQUENCE(10),{1,2}),2,-1),0,1))
D35:Y54D35=COUNTIFS(D24#,$A$2:$A$21)
C35:C54C35=SUM(D35:BA35)
Y56Y56=MIN(X56:X75)
Y57Y57=MAX(X56:X75)
Y59Y59=MIN(B56:W75)
Y60Y60=MAX(B56:W75)
X56:X75X56=AVERAGE($B56:W56)
Dynamic array formulas.


Whilst the difference between the Min & Max was a bit more than I expected, the average number of times a name occured was between 23.68 & 26.36, which is what I would expect.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Ok, did some testing, put the col F formula into cells D24:BA24 & counted how many times each name occurred & ran the calculation 22 times & these are the results.
+Fluff 1.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXY
24AveryAbigailElizabethMilaMilaAveryMilaMilaAveryEmilyEmilyAveryEmilyAveryAveryMilaAveryEmilyMilaMilaEmilyMila
25EmilyGiannaEllaSofiaEmilyEllaEmilySofiaEllaSofiaSofiaEmilySofiaEllaSofiaEmilySofiaSofiaAveryElizabethSofiaSofia
26SofiaHarperGiannaLunaSofiaLunaEllaElizabethAbigailEllaAbigailSofiaEllaLunaEllaGiannaLunaElizabethSofiaEllaElizabethElla
27EllaEvelynMiaHarperElizabethAbigailAbigailLunaCamilaLunaGiannaCamilaLunaAbigailLunaCamilaAbigailAbigailElizabethAbigailAbigailCamila
28AbigailIsabellaIsabellaMiaGiannaGiannaGiannaGiannaEvelynCamilaHarperHarperAbigailGiannaAbigailEvelynHarperCamilaAbigailEvelynCamilaHarper
29GiannaAmeliaAmeliaIsabellaCamilaCamilaCamilaIsabellaAmeliaEvelynEvelynMiaHarperEvelynGiannaMiaEvelynAmeliaCamilaIsabellaIsabellaEvelyn
30CamilaCharlotteSophiaSophiaEvelynEvelynIsabellaAmeliaSophiaMiaMiaSophiaIsabellaAmeliaCharlotteIsabellaMiaCharlotteIsabellaAmeliaCharlotteAmelia
31MiaAvaCharlotteCharlotteIsabellaIsabellaSophiaSophiaCharlotteIsabellaSophiaCharlotteSophiaSophiaAvaCharlotteIsabellaAvaCharlotteCharlotteAvaCharlotte
32AmeliaEmmaAvaEmmaAmeliaSophiaEmmaEmmaEmmaAmeliaAvaEmmaCharlotteAvaEmmaEmmaAmeliaEmmaAvaAvaEmmaEmma
33EmmaOliviaEmmaOliviaCharlotteCharlotteOliviaOliviaOliviaEmmaEmmaOliviaAvaOliviaOliviaOliviaCharlotteOliviaOliviaEmmaOliviaOlivia
34
35Abigail311100011010101110111110
36Sophia200011011110111100000000
37Amelia271110100111000100110101
38Elizabeth240010100100000000011110
39Ava260110000000101110011110
40Isabella290111111101001001101110
41Gianna261110111100100111000000
42Harper200101000000111000100001
43Mila210001101100000001001101
44Olivia260101001110010111011011
45Charlotte330111110010011011111111
46Evelyn200100110011100101100101
47Avery191000010010010110101000
48Emily231000101001111001010010
49Ella251010011011001110000101
50Sofia321001100101111010111011
51Mia191011000001110001100000
52Camila261000111011010001011011
53Emma321111001111110011010111
54Luna210001010101001110100000
55
56Abigail2825282126251725292725252526262423272421222024.5023.68
57Sophia2828242924242524282322212623222325222426222724.5526.36
58Amelia1425282824232820312325222723242930212824242624.86
59Elizabeth2525242224212529212722272524282525302228262725.0914
60Ava2522182623232325301927252229312322322126312624.9540
61Isabella2424222822262820222024322331233028272621252725.14
62Gianna2328372418243131292720222226262333192722222425.36
63Harper1723262321262129263030262619192227292529302524.95
64Mila2829212728252015223226273423292127273024262125.55
65Olivia2919253224252720202626232927212426192230232324.55
66Charlotte2423282622282726212426282323233128292724242925.64
67Evelyn2525212427273026172827292423232630262524222125.00
68Avery2925242425232127182722182820292423232529302424.45
69Emily2624282527232828222424262623242423281831262325.05
70Ella2527232327241918272626262426252515262421182623.68
71Sofia2926253028252934242429302125273022192628252426.36
72Mia2623232028252428293132243040212428212817222826.00
73Camila2429222225212526252118251923262418242524272923.73
74Emma2229232627372823312322222225262824292827322526.32
75Luna2921302030252426281827222421272023222524232524.27
Main
Cell Formulas
RangeFormula
D24:Y33D24=LET(Ex,FILTERXML("<k><m>"&SUBSTITUTE(C2,",","</m><m>")&"</m></k>","//m"),f,FILTER($A$2:$B$21,ISNA(MATCH($A$2:$A$21,IF(COUNTA(Ex)=1,C2,Ex),0))),INDEX(SORT(INDEX(SORTBY(f,RANDARRAY(ROWS(f))),SEQUENCE(10),{1,2}),2,-1),0,1))
D35:Y54D35=COUNTIFS(D24#,$A$2:$A$21)
C35:C54C35=SUM(D35:BA35)
Y56Y56=MIN(X56:X75)
Y57Y57=MAX(X56:X75)
Y59Y59=MIN(B56:W75)
Y60Y60=MAX(B56:W75)
X56:X75X56=AVERAGE($B56:W56)
Dynamic array formulas.


Whilst the difference between the Min & Max was a bit more than I expected, the average number of times a name occured was between 23.68 & 26.36, which is what I would expect.
Thank you so much for your assistance.

I did a test once again too.

My data has 254 rows, 254 names, I generate 5 names per row. I exclude 1 name in each row.
I can't publish my data, but just for comparison, look at the extreme values:

1 name appeard 14 times
1 name appeard 11 times
6 names appeard 10 times
---
9 names appeard 1 times
15 names appeard 2 times
35 names appeard 3 times

Since I get the results generated all the time, I usually see some names appearing up to 40 times while others get 0 shows.
So I wonder...
 
Upvote 0
I've run tests on that number of rows & names with 25 runs the min was 0 & the max 14 & each name appeared between 96 & 158
Considering you are picking 5 names out of 254, I would say that was about right.
 
Upvote 0
Thank you Fluff. If you have any idea - please let me know.
 
Upvote 0
About how to get the more even distribution thing solved )
 
Upvote 0
Fraid not. As I said with 5 names out of 245 getting a range of 0 to 14 is about what I would expect.
 
Upvote 0
I see.
Well, maybe there are other modifiers that may be added to the formula, that would let's say give more chance for higher rank names to be generated, and lower chance for lower rank names?

Like 30% of names from a higher rank end would get a boost and 30% of lower rank would get less if a chance...
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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