no repeats

Samgraphics

Board Regular
Joined
Jan 9, 2022
Messages
52
Office Version
  1. 2011
Platform
  1. MacOS
Hi, can someone please help me? I'm using this formula to select a random number between a range,
=CHOOSE(RANDBETWEEN(1,4),RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31)) but i would like it to check to see if the number is the same or a repeat and change it to the next number in the range. here is a snippet
Cell Formulas
RangeFormula
O2:O10O2=COUNTIF($C$2:$C$15,M2)
P2:P10P2=COUNTIF($D$2:$D$15,M2)
Q2:Q10Q2=COUNTIF($E$2:$E$15,M2)
R2:R10R2=COUNTIF($F$2:$F$15,M2)
S2:S10S2=COUNTIF($G$2:$G$15,M2)
T2:T10T2=COUNTIF($H$2:$H$15,K2)
U2:U10U2=COUNTIF($I$2:$I$15,K2)
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)+COUNTIF(O2,P2)+1
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,3),5,9,13)
AH2:AH10AH2=CHOOSE(RANDBETWEEN(1,5),10,12,15,17,27)
AI2:AI10AI2=CHOOSE(RANDBETWEEN(1,4),RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31))
AJ2:AJ10AJ2=CHOOSE(RANDBETWEEN(1,5),20,24,26,RANDBETWEEN(28,29),RANDBETWEEN(32,35))
AK2:AK10AK2=CHOOSE(RANDBETWEEN(1,3),3,5,7)
AL2:AL10AL2=CHOOSE(RANDBETWEEN(1,2),RANDBETWEEN(9,10),RANDBETWEEN(11,12))

So basically if AF is the same as AG or AH or AI or AJ or vise versa, AG is the same as AF,AH,AI, AJ and so on it will choose the next or a different random number in the range of numbers.

I tried this formula
=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)+COUNTIF(O2,P2)+1
but I don't think it's giving me the correct results.

Thank you for your time and help.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
1) Could you copy/paste whole data (from column C)?
2) cz you are using rand function. Try to hardcore value (i mean manual input), present the dupplicate, hightlight it, and what the desired output is.
 
Upvote 0
1) Could you copy/paste whole data (from column C)?
2) cz you are using rand function. Try to hardcore value (i mean manual input), present the dupplicate, hightlight it, and what the desired output is.
Hi Bebo, thank you for the reply. here is the data from column c.
STATISTICAL NUMBER GENERATOR BY column 2022.xlsx
CDEFGHIJMNOPQRSTUVAFAGAHAIAJAKAL
2141018321913300001059273034511
3491625325623210001035103024511
43510333471032200003055153135512
5351724325124431000115515182839
641925313521154130004055272224312
7131418313371061010001125272520712
81213183467731020021813271932312
952223253531181100001049273128311
10157172051292010100221310252679
Sheet1
Cell Formulas
RangeFormula
N2:N10N2=COUNTIF($C$2:$G$15,M2)
O2:O10O2=COUNTIF($C$2:$C$15,M2)
P2:P10P2=COUNTIF($D$2:$D$15,M2)
Q2:Q10Q2=COUNTIF($E$2:$E$15,M2)
R2:R10R2=COUNTIF($F$2:$F$15,M2)
S2:S10S2=COUNTIF($G$2:$G$15,M2)
T2:T10T2=COUNTIF($H$2:$H$15,K2)
U2:U10U2=COUNTIF($I$2:$I$15,K2)
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)+COUNTIF(O2,P2)+1
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,3),5,9,13)
AH2:AH10AH2=CHOOSE(RANDBETWEEN(1,5),10,12,15,17,27)
AI2:AI10AI2=CHOOSE(RANDBETWEEN(1,4),RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31))
AJ2:AJ10AJ2=CHOOSE(RANDBETWEEN(1,5),20,24,26,RANDBETWEEN(28,29),RANDBETWEEN(32,35))
AK2:AK10AK2=CHOOSE(RANDBETWEEN(1,3),3,5,7)
AL2:AL10AL2=CHOOSE(RANDBETWEEN(1,2),RANDBETWEEN(9,10),RANDBETWEEN(11,12))


2. I don't understand exactly what you mean in the 2nd part of your reply, "Try to hardcore value (i mean manual input), present the duplicate, highlight it, and what the desired output is." My excel skill lever is very minimal. If you could please explain a bit more or maybe even give an example, that would be much appreciated. thank you again.
 
Upvote 0
AF to AL are random value. Try to hit F9 until it shows unexpected outcome.
Copy screen or copy/paste value then post it.
 
Upvote 0
AF to AL are random value. Try to hit F9 until it shows unexpected outcome.
Copy screen or copy/paste value then post it.
Hi, so some numbers in columns O to S have a very close frequency so I want the randbetween function to choose between them both but if I do it that way sometimes there are duplicates, so I'd like it to check to see if there is a duplicate then select the next random number in the range I specify in the randbetween function.
STATISTICAL NUMBER GENERATOR BY column 2022.xlsx
CDEFGHIJMNOPQRSTUVAFAGAHAIAJAKAL
2141018321913300001049273032510
3491625325623210001035173129711
43510333471032200003025132220710
53517243251244310001145102533311
64192531352115413000401973026511
7131418313371061010001131910192059
8121318346773102002121927312059
952223253531181100001025271920312
1015717205129201010024910924510
Sheet1
Cell Formulas
RangeFormula
N2:N10N2=COUNTIF($C$2:$G$15,M2)
O2:O10O2=COUNTIF($C$2:$C$15,M2)
P2:P10P2=COUNTIF($D$2:$D$15,M2)
Q2:Q10Q2=COUNTIF($E$2:$E$15,M2)
R2:R10R2=COUNTIF($F$2:$F$15,M2)
S2:S10S2=COUNTIF($G$2:$G$15,M2)
T2:T10T2=COUNTIF($H$2:$H$15,K2)
U2:U10U2=COUNTIF($I$2:$I$15,K2)
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,4),5,9,13,19)
AH2:AH10AH2=CHOOSE(RANDBETWEEN(1,6),7,10,RANDBETWEEN(12,13),15,17,27)
AI2:AI10AI2=CHOOSE(RANDBETWEEN(1,5),9,RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31))
AJ2:AJ10AJ2=CHOOSE(RANDBETWEEN(1,5),20,24,26,RANDBETWEEN(28,29),RANDBETWEEN(32,35))
AK2:AK10AK2=CHOOSE(RANDBETWEEN(1,3),3,5,7)
AL2:AL10AL2=CHOOSE(RANDBETWEEN(1,2),RANDBETWEEN(9,10),RANDBETWEEN(11,12))


so in row 7 if AG already has 19 then change AI to the next random number in the range and so on.

Thank you
 
Upvote 0
There are 2 options:
Option1: using helper table of random number list for each column from AH13 to AL24
Book2
AFAGAHAIAJAKAL
1
239122235510
34973135311
445173124312
5413102520712
64527192039
7419152532311
819152524710
9213271826712
1031327920712
11
12random list
13792039
147920510
15101824711
1610192412
17122226
18132526
19153028
20153129
211732
221735
2327
2427
Sheet1
Cell Formulas
RangeFormula
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,4),5,9,13,19)
AH2:AH10AH2=INDEX(AH$13:AH$24,AGGREGATE(15,6,(ROW(AH$13:AH$24)-ROW(AH$13)+1)/(COUNTIF($AF2:AG2,AH$13:AH$24)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AG2,AH$13:AH$24)=0)))))
AI2:AI10AI2=INDEX(AI$13:AI$20,AGGREGATE(15,6,(ROW(AI$13:AI$20)-ROW(AI$13)+1)/(COUNTIF($AF2:AH2,AI$13:AI$20)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AH2,AI$13:AI$20)=0)))))
AJ2:AJ10AJ2=INDEX(AJ$13:AJ$22,AGGREGATE(15,6,(ROW(AJ$13:AJ$22)-ROW(AJ$13)+1)/(COUNTIF($AF2:AI2,AJ$13:AJ$22)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AI2,AJ$13:AJ$22)=0)))))
AK2:AK10AK2=INDEX(AK$13:AK$15,AGGREGATE(15,6,(ROW(AK$13:AK$15)-ROW(AK$13)+1)/(COUNTIF($AF2:AJ2,AK$13:AK$15)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AJ2,AK$13:AK$15)=0)))))
AL2:AL10AL2=INDEX(AL$13:AL$16,AGGREGATE(15,6,(ROW(AL$13:AL$16)-ROW(AL$13)+1)/(COUNTIF($AF2:AK2,AL$13:AL$16)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AK2,AL$13:AL$16)=0)))))


Option 2: Hardcoding the value items, not using helper table
Cell Formulas
RangeFormula
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,4),5,9,13,19)
AH2:AH10AH2=INDEX({7;7;10;10;12;13;15;15;17;17;27;27},AGGREGATE(15,6,({1;2;3;4;5;6;7;8;9;10;11;12})/(COUNTIF($AF2:AG2,{7;7;10;10;12;13;15;15;17;17;27;27})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AG2,{7;7;10;10;12;13;15;15;17;17;27;27})=0)))))
AI2:AI10AI2=INDEX({9;9;18;19;22;25;30;31},AGGREGATE(15,6,({1;2;3;4;5;6;7;8})/(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0)))))
AJ2:AJ10AJ2=INDEX({20;20;24;24;26;26;28;29;32;35},AGGREGATE(15,6,({1;2;3;4;5;6;7;8;9;10})/(COUNTIF($AF2:AI2,{20;20;24;24;26;26;28;29;32;35})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AI2,{20;20;24;24;26;26;28;29;32;35})=0)))))
AK2:AK10AK2=INDEX({3;5;7},AGGREGATE(15,6,({1;2;3})/(COUNTIF($AF2:AJ2,{3;5;7})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AJ2,{3;5;7})=0)))))
AL2:AL10AL2=INDEX({9;10;11;12},AGGREGATE(15,6,({1;2;3;4})/(COUNTIF($AF2:AK2,{9;10;11;12})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AK2,{9;10;11;12})=0)))))
 
Upvote 0
Solution
There are 2 options:
Option1: using helper table of random number list for each column from AH13 to AL24
Book2
AFAGAHAIAJAKAL
1
239122235510
34973135311
445173124312
5413102520712
64527192039
7419152532311
819152524710
9213271826712
1031327920712
11
12random list
13792039
147920510
15101824711
1610192412
17122226
18132526
19153028
20153129
211732
221735
2327
2427
Sheet1
Cell Formulas
RangeFormula
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,4),5,9,13,19)
AH2:AH10AH2=INDEX(AH$13:AH$24,AGGREGATE(15,6,(ROW(AH$13:AH$24)-ROW(AH$13)+1)/(COUNTIF($AF2:AG2,AH$13:AH$24)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AG2,AH$13:AH$24)=0)))))
AI2:AI10AI2=INDEX(AI$13:AI$20,AGGREGATE(15,6,(ROW(AI$13:AI$20)-ROW(AI$13)+1)/(COUNTIF($AF2:AH2,AI$13:AI$20)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AH2,AI$13:AI$20)=0)))))
AJ2:AJ10AJ2=INDEX(AJ$13:AJ$22,AGGREGATE(15,6,(ROW(AJ$13:AJ$22)-ROW(AJ$13)+1)/(COUNTIF($AF2:AI2,AJ$13:AJ$22)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AI2,AJ$13:AJ$22)=0)))))
AK2:AK10AK2=INDEX(AK$13:AK$15,AGGREGATE(15,6,(ROW(AK$13:AK$15)-ROW(AK$13)+1)/(COUNTIF($AF2:AJ2,AK$13:AK$15)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AJ2,AK$13:AK$15)=0)))))
AL2:AL10AL2=INDEX(AL$13:AL$16,AGGREGATE(15,6,(ROW(AL$13:AL$16)-ROW(AL$13)+1)/(COUNTIF($AF2:AK2,AL$13:AL$16)=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AK2,AL$13:AL$16)=0)))))


Option 2: Hardcoding the value items, not using helper table
Cell Formulas
RangeFormula
AF2:AF10AF2=CHOOSE(RANDBETWEEN(1,4),1,RANDBETWEEN(2,3),4,7)
AG2:AG10AG2=CHOOSE(RANDBETWEEN(1,4),5,9,13,19)
AH2:AH10AH2=INDEX({7;7;10;10;12;13;15;15;17;17;27;27},AGGREGATE(15,6,({1;2;3;4;5;6;7;8;9;10;11;12})/(COUNTIF($AF2:AG2,{7;7;10;10;12;13;15;15;17;17;27;27})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AG2,{7;7;10;10;12;13;15;15;17;17;27;27})=0)))))
AI2:AI10AI2=INDEX({9;9;18;19;22;25;30;31},AGGREGATE(15,6,({1;2;3;4;5;6;7;8})/(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0)))))
AJ2:AJ10AJ2=INDEX({20;20;24;24;26;26;28;29;32;35},AGGREGATE(15,6,({1;2;3;4;5;6;7;8;9;10})/(COUNTIF($AF2:AI2,{20;20;24;24;26;26;28;29;32;35})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AI2,{20;20;24;24;26;26;28;29;32;35})=0)))))
AK2:AK10AK2=INDEX({3;5;7},AGGREGATE(15,6,({1;2;3})/(COUNTIF($AF2:AJ2,{3;5;7})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AJ2,{3;5;7})=0)))))
AL2:AL10AL2=INDEX({9;10;11;12},AGGREGATE(15,6,({1;2;3;4})/(COUNTIF($AF2:AK2,{9;10;11;12})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AK2,{9;10;11;12})=0)))))
Hi, sorry for the late reply but and Thank you so much for your help and your time. I spent most of the day yesterday trying to understand the formula but I don’t. The formula works perfectly but I m just worried that if I need to change the values that I wouldn’t know how I would need to update the helper column. For example, the list I sent you only has ten rows, the actual data is a 100 rows, also as time goes on the values in the choose formula changes as does the randbetween. For example in column AH2:AH10 you have 7,7,10,10,12,13,15,15,17,17,27,27 and in column AI2:AI10 you have 9,9,18,19,22,25,30,31. I noticed that values before the randbetween and values after the randbetween you entered them twice in the random list helper column and values in between the randbetween like this one, =CHOOSE(RANDBETWEEN(1,5),9,RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31)), you entered once. So although 22 and 25 are whole values like 9, you still only entered them once but entered 9 twice. Is that because they were between two randbetweens? Can you please explain a little how this formula works in case I need to change values and also if there are 100 rows does the random list help column stay the same or does it need to change? Thank you so much. I also noticed that you didn’t do anything to column AF2:AF10 and AG2:AG10, I don’t understand why? But that because my excel knowledge is so limited at the moment. Thank you so much.
 
Upvote 0
I also noticed that you didn’t do anything to column AF2:AF10 and AG2:AG10, I don’t understand why?
First 2 columns, they are all unique numbers (no dupplicate) then leave initial formula. From 3rd there are dupplicate need to remove then using helper column. (3rd: number 13, 4th: number 9,...)
In your actual file, if dupplicate value appear from 2nd columns, put helper from that columns.
So although 22 and 25 are whole values like 9, you still only entered them once but entered 9 twice.
Your initial formula in #5 for AI:
=CHOOSE(RANDBETWEEN(1,5),9,RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31))
tell me that: 9,{18 or 19},22,25,{30 or 31}
there five number (or group number) have 20% probability for each number or group. Because each number in group share 50% : 18 & 19 have 10% probability each.
So, that formula is equal: =CHOOSE(RANDBETWEEN(1,10),9,9,18,19,22,22,25,25,30,31) for each number have 10% probability.
In my solution:
AI2=INDEX({9;9;18;19;22;25;30;31},AGGREGATE(15,6,({1;2;3;4;5;6;7;8})/(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0)))))
In which: INDEX({9;9;18;19;22;25;30;31} try to random 8 numbers with same probability for each (9,22,25 have double probability bcz they appear twice)
Next: (COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0) returns 0 (if value already exists in AF2:AH2) 1 if not.
then ({1;2;3;4;5;6;7;8})/(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0) returns sequence 1 to 8, but 0 if value exists in AF2:AH2
then AGGREGATE(..., randbetween) try to random the number within 1-8

The formula works perfectly but I m just worried that if I need to change the values that I wouldn’t know how I would need to update the helper column.
Helper columns could be put anywhere in worksheet, follow this logic:
For ex, you have 3 numbers: 1,2,3 but you want probability of 3 is 2 times greater than 1 and 2 . Helper column is: 1,2,3,3, then randbetween (1,4) of this helper list
If 3 times: 1,2,3,3,3 and randbetween(1,5)
 
Upvote 0
First 2 columns, they are all unique numbers (no dupplicate) then leave initial formula. From 3rd there are dupplicate need to remove then using helper column. (3rd: number 13, 4th: number 9,...)
In your actual file, if dupplicate value appear from 2nd columns, put helper from that columns.

Your initial formula in #5 for AI:
=CHOOSE(RANDBETWEEN(1,5),9,RANDBETWEEN(18,19),22,25,RANDBETWEEN(30,31))
tell me that: 9,{18 or 19},22,25,{30 or 31}
there five number (or group number) have 20% probability for each number or group. Because each number in group share 50% : 18 & 19 have 10% probability each.
So, that formula is equal: =CHOOSE(RANDBETWEEN(1,10),9,9,18,19,22,22,25,25,30,31) for each number have 10% probability.
In my solution:
AI2=INDEX({9;9;18;19;22;25;30;31},AGGREGATE(15,6,({1;2;3;4;5;6;7;8})/(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0),RANDBETWEEN(1,SUMPRODUCT(--(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0)))))
In which: INDEX({9;9;18;19;22;25;30;31} try to random 8 numbers with same probability for each (9,22,25 have double probability bcz they appear twice)
Next: (COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0) returns 0 (if value already exists in AF2:AH2) 1 if not.
then ({1;2;3;4;5;6;7;8})/(COUNTIF($AF2:AH2,{9;9;18;19;22;25;30;31})=0) returns sequence 1 to 8, but 0 if value exists in AF2:AH2
then AGGREGATE(..., randbetween) try to random the number within 1-8


Helper columns could be put anywhere in worksheet, follow this logic:
For ex, you have 3 numbers: 1,2,3 but you want probability of 3 is 2 times greater than 1 and 2 . Helper column is: 1,2,3,3, then randbetween (1,4) of this helper list
If 3 times: 1,2,3,3,3 and randbetween(1,5)
HI, thank you so much for that explanation. It's still a bit over my head, but I think I got it for the most part and I really appreciate the time you took to help me and then to explain it to me. I'm truly grateful.
Thank you so much.
Thank you
I think this helps me in the event I need to change the values which I've tried and gotten correct results for .
thank you
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,755
Members
448,989
Latest member
mariah3

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