Even Sum of Colums of a Random generated array

vbafreak

New Member
Joined
Dec 17, 2014
Messages
1
I am sure you can tell by the title this is going to be fun!

I have an array of random number of card players getting a random (but equal) number of cards. The cards are all numbered based on "power". So card 50 is weaker than card 49. I have the random number generator all set up to fill in the blanks but I need the sum of any one hand to be similar to any other hand. I know that everyone will hate the "TL" Variable.

The Similar part or standard deviation is the part I am not sure about. I would like the results to be as close to exact matching sums as possible but if not possible then as close as mathematically possible.

I have done the easy part already :)

Code:
Sub randomNumbers()
    Dim TL As String
    Dim LR As String
    Dim Low As Double
    Dim High As Double
    ActiveSheet.ClearContents
    TL = Application.InputBox("Top Left of Range")
    LR = Application.InputBox("Bottom Right of Range")
    Range(TL, LR).Select
    Low = Application.InputBox("Enter Lowest card rank", Type:=1)
    High = Application.InputBox("Enter Highest card rank", Type:=1)
    Selection.Clear
    For Each cell In Selection.Cells
        If WorksheetFunction.CountA(Selection) = (High - Low + 1) Then Exit For
        Do
            rndNumber = Int((High - Low + 1) * Rnd() + Low)
        Loop Until Selection.Cells.Find(rndNumber, LookIn:=xlValues, lookat:=xlWhole) Is Nothing
        cell.Value = rndNumber
    Next
    Lastrow = ActiveSheet.UsedRange.Rows.Count
    LastCol = ActiveSheet.UsedRange.Columns.Count
    Range(Cells(Lastrow + 2, [1]), Cells(Lastrow + 2, LastCol)).Formula = "=SUM(A1:A" & Lastrow & ")"
    
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
card 1 is say 50 strength and card 50 is say 1 strength, so ave strength is 25, so if all cards are dealt to 5 players each hand must equal 25 or as close as possible

but if 10 cards are dealt to each of 3 players the average can be from strength 35 to strength 15, so if you select 30 cards at random first determine the average strength and then distribute to number of players accordingly

you can get them mathematically equal but hands can be normallish or very strangely distibuted

I would rely on randomise function to deal the hands
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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