How To Calculate The Number Of Possible Combinations In A Lottery Application
Latest Casino News TopCasinoGames.eu 10 Apr , 2017 0
One of the difficulties in generating lotto numbers is knowing the amount of combinations needed to cover all the potential winners.
Calculating Possible Combinations In A Lottery Draw
The formula is taken directly from probability theory and makes use of the factorial method. A factorial is simply a number multiplied by lesser numbers down to one.
So, the factorial of 4 is 4x3x2x1=24 and is written as 4!
Here's the general formula for working out the amount of combinations in any given set of numbers.
Number of Combinations=(n!/(n-k)!)/k!Where n is all the numbers available to choose from and k is how many in each combination.
Let's take a simple sports example to explain this further.
If there are 6 players to choose from, how many possible teams of 4 players are there?
Working through our formula
n=6, k=4n!=6X5x4x3x2x1=720
k!=4x3x2x1=24
n-k=2Number of combinations=(720/2)/24
=360/24
=15
Working this out manually we get the 15 combinations.
1234
1235
1236
1245
1246
1256
1345
1346
1356
1456
2345
2346
2356
2456
3456
Using An Excel Formula To Calculate The Possible Lottery Combinations
With a lottery application, it's likely the numbers will be larger so you might need a more efficient way of calculating the formula.
With Excel, you can use the following:
=COMBIN(n,k)So typing =combin(6,4) in any cell should give an output of 15
Creating A Function In VBA To Calculate Lotto Combinations
Using VBA to do the same calculation is a little more complex; because there is no factorial function in Visual Basic, you need to create your own.
Here's an example.
n = 6
factorial = n
For x = 5 To 1 Step -1
factorial = factorial * x
Next
Debug.Print factorial
To apply the formula in VBA you would probably wrap the factorial code is a separate function.
Sub test1()n = 6
k = 4
d = n - k
nFac = fac(n)
kFac = fac(k)
dFac = fac(d)
p = (nFac / dFac) / kFac
Debug.Print p
End SubFunction fac(j)
factorial = j
For x = j - 1 To 1 Step -1
factorial = factorial * x
Next
fac = factorial
End Function
The VBA code is complex, compared to the simplicity of the Excel formula but it's likely that to create a flexible lotto application you'll need some calculations done directly in code.
Summary
This article has shown one method of calculating the number of combinations in a lottery draw. While some players work out the formula manually, it's good idea to know how to automate the task, ensuring any lotto application has the flexibility required.
[ad_2]
Source by A. Lewis Gibson