Creating a random sequence of items from a weighted list with no duplicates

stevesherrin

New Member
Joined
Oct 31, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I work for a playing card company and we often get calls for randomized expansion packs for games created from a pool of all the cards in the game. Some cards are more rare than others so should show up less times As an example, one game has a pool of 40 cards and I need to create 500 random 9 card sets but some cards are twice as likely to be drawn as others. I currently create a list of multiple copies of the filenames of each card, so each rare card appears once in my filename pool. The formula I use is :

=INDEX(filenames,(INDEX(UNIQUE(RANDARRAY(10^4, 1, 1, 217, TRUE)), SEQUENCE(9))))

This works well but there are 2 issues with it:

1) In some cases there are 4-5 rarity levels, some cards needing to appear 220 times in the filename list. The list is over 3000 filenames long. It is very time-consuming (and tedious) t put this list together.
2) While it minimizes duplicates within a single set, it doesn't completely get rid of them, especially with larger sets (36-54 random cards per set).

I have been trying to use a true weighted formula for this but the formulas I have found for weighted pulls from a list do not generate sequences (ie- a list of 9 cards)... They only produce one. The option that has been offered is putting the formula in one cell and dragging the handle down to duplicate the formula the 8 cells beneath it. While this works, there's no way to make the separate cards unique since they are drawn separately (since they are not a sequence created by a single formula in one cell that auto generates 9 entries in the column.

This new formula is:

=INDEX(filenames,MATCH(RAND(),cumulative))

filenames is a named range in the excel sheet (B3:B8) and cumulative is a named range (D3:D8)

weighted random.xlsx
ABCDEF
1valueprobabilitycumulativeweighted random
2
3ape.jpg5%0.00frog.jpg
4cat.jpg10%0.05
5dog.jpg10%0.15
6bear.jpg20%0.25
7dolphin.jpg25%0.45
8frog.jpg30%0.70
Sheet1
Cell Formulas
RangeFormula
F3F3=INDEX(filenames,MATCH(RAND(),cumulative))
D3:D8D3=SUM(D2,C2)
Named Ranges
NameRefers ToCells
cumulative=Sheet1!$D$3:$D$8F3, D4
filenames=Sheet1!$B$3:$B$8F3


Is there a way to modify this to create a sequence of random items from the list in a column and to prevent duplicates? Or maybe a VB script? Unfortunately I am a noob to excel and have no VB experience at all.

Thanks in advance for any suggestions you may have.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I work for a playing card company and we often get calls for randomized expansion packs for games created from a pool of all the cards in the game. Some cards are more rare than others so should show up less times As an example, one game has a pool of 40 cards and I need to create 500 random 9 card sets but some cards are twice as likely to be drawn as others. I currently create a list of multiple copies of the filenames of each card, so each rare card appears once in my filename pool. The formula I use is :

=INDEX(filenames,(INDEX(UNIQUE(RANDARRAY(10^4, 1, 1, 217, TRUE)), SEQUENCE(9))))

This works well but there are 2 issues with it:

1) In some cases there are 4-5 rarity levels, some cards needing to appear 220 times in the filename list. The list is over 3000 filenames long. It is very time-consuming (and tedious) t put this list together.
2) While it minimizes duplicates within a single set, it doesn't completely get rid of them, especially with larger sets (36-54 random cards per set).

I have been trying to use a true weighted formula for this but the formulas I have found for weighted pulls from a list do not generate sequences (ie- a list of 9 cards)... They only produce one. The option that has been offered is putting the formula in one cell and dragging the handle down to duplicate the formula the 8 cells beneath it. While this works, there's no way to make the separate cards unique since they are drawn separately (since they are not a sequence created by a single formula in one cell that auto generates 9 entries in the column.

This new formula is:

=INDEX(filenames,MATCH(RAND(),cumulative))

filenames is a named range in the excel sheet (B3:B8) and cumulative is a named range (D3:D8)

weighted random.xlsx
ABCDEF
1valueprobabilitycumulativeweighted random
2
3ape.jpg5%0.00frog.jpg
4cat.jpg10%0.05
5dog.jpg10%0.15
6bear.jpg20%0.25
7dolphin.jpg25%0.45
8frog.jpg30%0.70
Sheet1
Cell Formulas
RangeFormula
F3F3=INDEX(filenames,MATCH(RAND(),cumulative))
D3:D8D3=SUM(D2,C2)
Named Ranges
NameRefers ToCells
cumulative=Sheet1!$D$3:$D$8F3, D4
filenames=Sheet1!$B$3:$B$8F3


Is there a way to modify this to create a sequence of random items from the list in a column and to prevent duplicates? Or maybe a VB script? Unfortunately I am a noob to excel and have no VB experience at all.

Thanks in advance for any suggestions you may have.
How do you calculate the probability?
 
Upvote 0
This is a stars-and-bars combinatorics problem, with 9 stars (cards) partitioned into like names by 5 bars. So for example,

ape ape | cat | dog dog dog | bear bear bear | |

is a possibility, and so is

| cat | dog dog | bear bear bear | dolphin | frog frog

The five bars can appear in any combination of the 9+5 = 14 slots, so there are COMBIN(14, 5) = 2002 possible nine-card combinations, but not all are valid because you have limited numbers of each card (no ape ape ape | ... because there are only 2 ape cards in the original 40-card deck). That reduces it to 1299, and I think (still pondering) that those are equally likely. I can post a workbook that generates those combinations tomorrow if you're interested.
 
Upvote 0
This is a stars-and-bars combinatorics problem, with 9 stars (cards) partitioned into like names by 5 bars. So for example,

ape ape | cat | dog dog dog | bear bear bear | |

is a possibility, and so is

| cat | dog dog | bear bear bear | dolphin | frog frog

The five bars can appear in any combination of the 9+5 = 14 slots, so there are COMBIN(14, 5) = 2002 possible nine-card combinations, but not all are valid because you have limited numbers of each card (no ape ape ape | ... because there are only 2 ape cards in the original 40-card deck). That reduces it to 1299, and I think (still pondering) that those are equally likely. I can post a workbook that generates those combinations tomorrow if you're interested.

shg,

That may be a bit beyond me but I would be very interested in seeing what the solution looks like

Thanks for your help!
 
Upvote 0
How do you calculate the probability?
HighAndWilder,

The probability is actually provided by the client... for instance, all ultra-rare cards have a probability of 1, rare cards all have a probability of 10 (10 times as likely to be selected as ultra rare) and common a probability of 100 (100 times as likely as ultra-rare, 10 times as likely as rare).
 
Upvote 0
This is a stars-and-bars combinatorics problem, with 9 stars (cards) partitioned into like names by 5 bars. So for example,

ape ape | cat | dog dog dog | bear bear bear | |

is a possibility, and so is

| cat | dog dog | bear bear bear | dolphin | frog frog

The five bars can appear in any combination of the 9+5 = 14 slots, so there are COMBIN(14, 5) = 2002 possible nine-card combinations, but not all are valid because you have limited numbers of each card (no ape ape ape | ... because there are only 2 ape cards in the original 40-card deck). That reduces it to 1299, and I think (still pondering) that those are equally likely. I can post a workbook that generates those combinations tomorrow if you're interested.
shg,

One more thing based on your response... there is no issue with having multiple sets witht he same combination of cards, just not having any duplicates within one set
 
Upvote 0
>> there is no issue with having multiple sets with he same combination of cards, just not having any duplicates within one set

What does that mean?? What's OK, what isn't?
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,083
Members
453,021
Latest member
Justyna P

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