Randomize as equally possible

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have a list or Agent Names from column A
Say first set of rows is A2:A50

I want to generate random number between 1,3 but want to make sure its eventually spread or as even as evenly possible

How can I achieve this tweaking this randbetween formula
=Randbetween(1,3)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Do you mean equal amounts of 1s, 2s, and 3s, as close as possible? Then try:

Book1
AB
1NameCode
2A1
3B1
4C2
5D1
6E3
7F2
8G3
9H2
10I1
11J3
12K3
13L1
14M2
15N3
16O1
17P2
18Q2
19R1
20S2
21T3
22U2
23V1
24W3
25X2
26Y1
27Z3
Sheet5
Cell Formulas
RangeFormula
B2:B27B2=LET(a,COUNTA(A2:A50),SORTBY(INT(SEQUENCE(a,,,3/a)),RANDARRAY(a)))
Dynamic array formulas.
 
Upvote 0
An absolute legend thank you

I need to tweak this slightly where i need to generate random numbers in the range but for some of the names i need to generate 4 to 7, 8 to 9 etc

I have a table that has the look up group value thats stored in column B

So Data
Agents, Grouping, Value
A. GroupA. 20
B Group A. 30
C. GroupB. 10
D. GroupC. 9
E. GroupB. 15

Etc

Lookup Table

Grouping, RandStart, RandEnd
GroupA. 1. 3
GroupB. 5. 7
GroupC. 9. 11

So that essentially that lookup part where the sequence has 3 needs to be replaced bu looking up the group from column B in lookuptable to see what numbers i need to equally spread for that grouping

Hoping that makes sense
 
Upvote 0
I had a go



=LET(a, COUNTIF(A2:A50,”GroupA”),SORTBY(INT(SEQUENCE(a,,, Index(lookuptable,Match(“GroupA”, LookupTable(“C2:C7”,0))/a)),RANDARRAY(a))



I have 6 groups



Problem i have is how can i make the lookup and counta/countif part dynamic



I can do it multiple times for each group but was hoping to do in 1 formula
 
Upvote 0
Hi Eric - so i tried to tweak formula to give diff values based on grouping so changed formula for each group but it looks like it only works for first group so not 1 to 3 and not 5 to 7, 9 to 11 etc (starting point not right)

Lookup Table

GroupSort ByRand StartRand End
0 - 3 Months
1​
1​
3​
3 - 6 Months
2​
5​
7​
6 - 12 Months
3​
9​
11​
1 - 2 Years
4​
13​
15​
2 - 4 years
5​
17​
19​
5 Years +
6​
21​
23​

AgentGroupValueRandom Number
A10 - 3 Months
25.00%​
2​
A90 - 3 Months
25.00%​
1​
A130 - 3 Months
2.00%​
1​
A210 - 3 Months
21.00%​
2​
A250 - 3 Months
21.00%​
3​
A330 - 3 Months
27.00%​
2​
A370 - 3 Months
21.00%​
1​
A450 - 3 Months
11.00%​
3​
A23 - 6 Months
16.00%​
11​
A103 - 6 Months
21.00%​
10​
A143 - 6 Months
25.00%​
7​
A223 - 6 Months
21.00%​
5​
A263 - 6 Months
29.00%​
6​
A343 - 6 Months
7.00%​
9​
A383 - 6 Months
12.00%​
5​
A463 - 6 Months
13.00%​
8​
A36 - 12 Months
19.00%​
15​
A116 - 12 Months
2.00%​
11​
A156 - 12 Months
21.00%​
14​
A236 - 12 Months
9.00%​
13​
A276 - 12 Months
11.00%​
9​
A356 - 12 Months
8.00%​
10​
A396 - 12 Months
17.00%​
17​
A476 - 12 Months
3.00%​
18​

Formulas used for each group(First Group)

=LET(a,COUNTA(R4:R11),SORTBY(INT(SEQUENCE(a,,INDEX($H$4:$H$9,MATCH(R4,$F$4:$F$9,0)),INDEX($I$4:$I$9,MATCH(R4,$F$4:$F$9,0))/a)),RANDARRAY(a)))
Should generate numbers from 1 to 3 equally

Second Group
=LET(a,COUNTA(R12:R19),SORTBY(INT(SEQUENCE(a,,INDEX($H$4:$H$9,MATCH(R12,$F$4:$F$9,0)),INDEX($I$4:$I$9,MATCH(R12,$F$4:$F$9,0))/a)),RANDARRAY(a)))

Should generate numbers from 5 to 7 equally which it aint

Third Group Etc
=LET(a,COUNTA(R20:R27),SORTBY(INT(SEQUENCE(a,,INDEX($H$4:$H$9,MATCH(R20,$F$4:$F$9,0)),INDEX($I$4:$I$9,MATCH(R20,$F$4:$F$9,0))/a)),RANDARRAY(a)))
Should generate numbers from 9 to 1 equally which it aint

etc
 
Upvote 0
I wish you'd explained the whole problem first, this is a much trickier problem. This is about the best I could come up with:

Book1
ABCDEFGHIJKLMNO
1AgentGroupingValueGroupingRandStartRandEndRandom Lists
2AGroupA3GroupA13321213
3BGroupB6GroupB5766575
4CGroupB6GroupC91111109
5DGroupB5GroupD121313121213
6EGroupA2GroupE151715171615151617
7FGroupC11GroupF202520
8GGroupD13
9HGroupA1
10IGroupF20
11JGroupE15
12KGroupC10
13LGroupE17
14MGroupC9
15NGroupE16
16OGroupE15
17PGroupB7
18QGroupA2
19RGroupD12
20SGroupE15
21TGroupE16
22UGroupA1
23VGroupD12
24WGroupD13
25XGroupA3
26YGroupE17
27ZGroupB5
Sheet6
Cell Formulas
RangeFormula
I2:N2,I7,I6:O6,I5:L5,I4:K4,I3:M3I2=LET(a,COUNTIF($B$2:$B$27,E2),SORTBY(INT(SEQUENCE(,a,F2,(G2-F2+1)/a)),RANDARRAY(,a)))
C2:C27C2=INDEX($I$2:$AA$7,MATCH(B2,$E$2:$E$7,0),COUNTIF(B$2:B2,B2))
Dynamic array formulas.


Next to your table with the groups and ranges, I added the formula to create a random, evenly distributed list for each group. You can hide this, or put it on another sheet. Then the C2 formula, which you have to drag down, just does a lookup for the value.

I tried to come up with a single cell formula, and I think it's possible, but it was giving me a headache! It would also be much easier with some of the newer functions like DROP and VSTACK, which my version of Excel doesn't have. See if this does what you want, and if so, start another thread to see if someone with the newer functions might take a shot at a single cell formula.
 
Upvote 0
Thank you so much Eric - i really appreciate your help

where did i go wrong in the original formula if i was to use for each group so the start and end works as expected?

=LET(a,COUNTA(R4:R11),SORTBY(INT(SEQUENCE(a,,INDEX($H$4:$H$9,MATCH(R4,$F$4:$F$9,0)),INDEX($I$4:$I$9,MATCH(R4,$F$4:$F$9,0))/a)),RANDARRAY(a)))
 
Upvote 0
I think this is where i was messing up based on your latest post

=LET(a,COUNTA(R4:R11),
SORTBY(INT(SEQUENCE(
a,,INDEX($H$4:$H$9,MATCH(R4,$F$4:$F$9,0)),(INDEX($I$4:$I$9,MATCH(R4,$F$4:$F$9,0)) - INDEX($H$4:$H$9,MATCH(R4,$F$4:$F$9,0)) + 1)/a)),
RANDARRAY(a)))
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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