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
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