Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Superseded Normal Distribution Lotto Record Covers
 LottoPoster Forums : WORLD RECORD LOTTO COVERS (WHEELS WITH GUARANTEE) : Best Yield Normal Distribution Lotto Covers : Superseded Normal Distribution Lotto Record Covers
Message Icon Topic: PROBABILITY PRIMER OR REFRESHER BY LOTTO ANALYSIS Post Reply Post New Topic
Author Message
Colin F
Lotto Systems Tester Creator & Analyst
Lotto Systems Tester Creator & Analyst
Avatar
To dream the impossible dream ...

Joined: September 30 2004
Location: Australia
Online Status: Offline
Posts: 678
Quote Colin F Replybullet Topic: PROBABILITY PRIMER OR REFRESHER BY LOTTO ANALYSIS
    Posted: November 01 2009 at 9:59pm
Probability Primer or Refresher
using Lotto Number Analysis and VBA or VB code

by Colin Fairbrother


In understanding the numbers in Lotto coming to grips with at least an informal knowledge of probability is essential. Over the more than 10 years of my involvement in Lotto number analysis the absurdities I have come across from various websites point to a lack of understanding of probability or an errant application of the knowledge. I have no pretensions to be a mathematician so this is written from the point of view of what someone needs to know if intending to write some code in the Lotto Number analysis field of interest.

  1. Testing Environment
  2. Outcomes or Possibilities
  3. Probability and Odds
  4. Independent Events
  5. Factorial
  6. Permutations
        with replacement
        without replacement
  7. Combinations
        with replacement
       without replacement
  8. Calculating the Odds for the Prizes
  9. Providing an Excel User-Form Interface
Testing Environment
If you intend to seriously get involved in this subject then you need a programming test environment such as the debug window in Microsoft Excel, Access, Visual Basic, Visual C# or Visual C++. Excel is probably the most likely choice and the least known to get to the debug window - Click on Tools in the Menu bar then Macro | Visual Basic Editor or simply Alt + F11 - once in that environment from the menu click View and make sure the Immediate Window is selected. I will give examples in VBA which applies to both Excel and Access and you will need to place the code below in a module to test it out using the debug window. 

However, I strongly advise even if you are singularly competent in Excel or Access and haven't bought the Standard or higher version of Visual Studio, that you download and expand your expertise to include a modicum of familiarity with the free Visual Basic 2010 Express . The code given will work in VBA ie Access or Excel but for Visual Basic 2008 you will need to alter it slightly: -
  • include the argument in brackets after debug.Print.
  • use Continue For instead of GoTo a label to opt out of a For loop
  • choose a character other than e as a variable as it is already used. 

Anyone with programming experience knows that there is usually more than one way of tackling a task so improvement suggestions are welcome.  

Outcomes
The calculations done in Lotto analysis are referred to as discrete since for the scenario considered (the sample space) all the possible outcomes are known. For the Classic Lotto game where 6 integers (whole numbers) are randomly picked from a pool of 49 there are 49 possibilities for the first integer and you have 6 chances of getting it right which can be expressed as 6/49. For the second integer having used up 1 chance you only have 5 chances in 48 integers because an integer can only be used once. For the third integer 4 in 47, for the fourth 3 in 46, for the 5th 2 in 45 and for the 6th 1 in 44. Multiplying 6/49 x 5/48 x 4/47 x 3/46 x 2/45 x 1/44 = (6 x 5 x 4 x 3 x 2 x 1) / (49 x 48 x 47 x 46 x 45 x 44) = 720/10,068,347,520 = 1/13,983,816 which is the chance of getting 6 integers correct from the total number of possibilities or combinations with no regard for the order drawn. So, for 1 ticket or line your chances of success for 1st prize are 1 in 13,983,816. The draw is an outcome and there is only one for the scenario considered whether it be for the 6 winning integers or for the 20 ways 3 of those winning integers can be combined.

Probability and Odds
Playing just 1 or 1,000 tickets in Classic Lotto your chances of success as far as getting 6 integers correct is minuscule. Probability is expressed as a non-negative number between 0 and 1 for an outcome and when all the outcome probabilities are totaled the result is 1. A probability of 1 means the outcome is certain, 0,5 means a 50/50 chance and 0.0000000715 is extremely unlikely and actually the probability of getting the winning six in a Pick 6 Pool 49 Lotto game playing just one line.

As long as your lines are different any line is as good as another as far as getting 6 integers correct and this includes 1 2 3 4 5 6. I assure you that those who do not recognize this are in the loony brigade that tend to dominate this field of interest. So, Lotto number analysis with some intellectual rigor is more about maximizing your chances of getting the smaller prizes such as 3 integers correct.

Looking at 1 2 3 4 5 6 from the perspective of maximizing lower prize wins and playing a modest 20 lines with the integers in numerical order you may regard a line with 3 contiguous numerical order integers as being OK but not another line with 3 consecutive integers elsewhere in your set as the average ratio of consecutives for the set is exceeded. A line with 6 consecutive integers from this perspective may not be the best choice.

To emphasize the usually astronomical odds for jackpot style games  playing an unrealistic 1,000 lines your probability for getting 6 integers correct in Classic Lotto is 1000/13983816 or 0.0000715 and that of not getting 6 integers correct is  99.99999825 which are pretty well odds that you could safely stake your life on - certainly better than Russian roulette which is kaput 0.1666666 (16.66%) or reprieve 0.8333334 (83.33%).

Independent Events
A concept that needs to be thoroughly grasped to analyse Lotto in a rational way is that for a given scenario which we call an event where a number of objects that are identical but which have a unique distinguishing mark are randomly mixed and then a small number of these objects are randomly extracted then the outcome for this event HAS NO INFLUENCE on a repeat of this event. ie it is independent.


Factorial
An integer x when multiplied by itself minus 1 and then by that integer minus 1 and repeated until your last integer equals 1 is referred to as its factorial and abbreviated to x!. Understanding of Probability and Factorial go together. You can use your computer calculator usually located at C:\WINDOWS\SYSTEM32\calc.exe to calculate factorials. Looking at our classic Lotto example in Outcomes it should be obvious that  we can arrive at the number of possibilities by dividing 49! by 43! which by simplification becomes 49 x 48 x 47 x 46 x 45 x 44 and then dividing by 6! and this is known as the Binomial Coefficient.

An experienced Excel user probably knows there is a Worksheet function Fact that can be used as in x = Application.WorksheetFunction.Fact(7) but this is not available as easily in Access or Visual Basic and some would see it as a bit cumbersome.

To try out the following function press Alt F11 to bring up the Visual Basic Editor in Excel and make sure your layout is similar to this screen print. You may have to right click on VBA Project (Book 1) then insert | module to get a module in which to paste the code.

 

Function Fct(x As Byte) As Double
  Dim i As Integer, f As Double
    If x < 0 Or x > 170 Then
      Fct = 0
      Exit Function
    End If
    f = 1
    For i = 2 To x
      f = f * i
    Next i
    Fct = f
End Function
 
Typing for example ? Fct(6) in the immediate window then enter will return 720. If using Visual Basic 2008 you could use a Console project and type after Sub Main: -

Console.WriteLine(Fct(6))
Console.ReadLine()

Permutations

Permutations with repetition or replacement.

In the Pick 3 Lotto game we have 1,000 lines each of three digits which can be between 0 and 9 and the digits in one line can all be the same. The order is important for the highest payout.

To calculate the number of permutations with replacement in a Pick 3 Lotto game we simply multiply 10 x 10 x 10 or 10^3. If instead of 3 segments we had 10 then the total permutations with replacement would be 10 x 10 x 10 x 10 x 10 x 10 x 10 x 10 x 10 x 10 = 10^10 = 10,000,000,000 ie 10 billion.

Function for calculating Permutations with replacement: -

Function Perm(n As Byte, k As Byte) As Long
  ' n = Pool; k = Pick; n must be >= k; m must be between 0 and n 
    If n >= k Then
        Perm = n^k
    Else
        Perm = 0
    End If
End Function


Procedure for Enumerating Permutations with Replacement

Enter the following procedure code  after the Factorial function and then type PermWR(9,3) (don't need to preface with ? in this case) in the immediate window to enumerate all the permutations with replacement for Lotto game Pick 3: -

Public Sub EnumPermWR(Pl as Byte, Pk as Byte)

'Pl is Pool; Pk is Pick

Dim cnt As Long
Dim a As Byte, b As Byte, c As Byte

  
            For a = 0 To Pl - 1
               For b = 0 To Pl - 1
                 For c = 0 To Pl - 1
                      cnt = cnt + 1
                      'Debug.Print a & vbTab & b & vbTab & c
                Next c
              Next b
            Next a
          
      Debug.Print "Permutations with replacement for Pool " & Pl  & _
                          " Pick " & Pk & " = " & (Pl)^3       'also given by cnt

End Sub

Permutations without replacement

An example is the Australian add-on game called LottoStrike where from a Pool of 45 integers your entry line with 4 integers must have 1 or more integers correct for the order drawn.

It should be obvious (if you've read the previous terms in this page) that the possibilities for the first 4 integers is given by 45 x 44 x 43 x 42 = 3,575,880. An obvious formula where Pl is Pool and Pk is Pick: - is Pl! / (Pl - Pk)!

Function for calculating Permutations without repetition or replacement: -

Function PermWoRCalc(n As Byte, k As Byte) As Long
  ' n = Pool; k = Pick; n must be >= k; m must be between 0 and n 
    If n >= k Then
        PermWoRCalc = Fct(n) / Fct(n - k)
    Else
        PermWoRCalc = 0
    End If
End Function
 

Procedure for Enumerating Permutations without Repetition or Replacement

If you type PermWoR(45, 4) in the immediate window and then enter, the line with an index halfway through will be printed as well as the number of possibilities.

Public Sub EnumPermWoR(Pl As Byte, Pk As Byte)

'Pl is Pool and Pk is Pick

Dim cnt As Long, l As Long
Dim a As Byte, b As Byte, c As Byte, d As Byte

  Select Case Pk             'Pool 10 (0 to 9) Cnt is 5040
     Case 4
        'l = (Fct(Pl) / Fct(Pl - Pk)) / 2
        For a = 0 To Pl - 1
          For b = 0 To Pl - 1
              If b = a Then GoTo BP4_2
            For c = 0 To Pl - 1
                If c = b Or c = a Then GoTo BP4_3
              For d = 0 To Pl - 1
                  If d = c Or d = b Or d = a Then GoTo BP4_4
                      cnt = cnt + 1
                      'If cnt = l Then
                        'Debug.Print a & vbTab & b & vbTab & c & vbTab & d
                      'End If
BP4_4:
              Next d
BP4_3:
            Next c
BP4_2:
          Next b
        Next a
          
    Case 3    'For Pl 10 (0 to 9) cnt is 720 ie unmatched
            For a = 0 To Pl - 1
              For b = 0 To Pl - 1
                If b = a Then GoTo BP3_2
              For c = 0 To Pl - 1
                If c = b Or c = a Then GoTo BP3_3
                      cnt = cnt + 1
                      'Debug.Print a & vbTab & b & vbTab & c
BP3_3:
            Next c
BP3_2:
          Next b
        Next a
        
    End Select
          
    Debug.Print cnt

End Sub

Combinations

For a given Pool and Pick the number of Combinations without repetition of the integers, where the order of the integers is not important, is a subset of the number of Permutations without repetition. A simple case where the Pool is 3 ie 0, 1, 2 and the Pick is 3 means we have 3 x 2 x 1 = 6 Permutations but only 1 combination which can present 6 ways but is usually given in numerical order as 0 1 2 but is still the same combination as 0 2 1 or 1 0 2 or 1 2 0 or 2 0 1 or 2 1 0. 

Combinations without repetition (or replacement)

This applies to most Jackpot style games such as the classic Pool 49 Pick 6 game.

Just like Factorial there is a worksheet function you could use Combin but VBA doesn't know anything about it unless you qualify the name as in Application.WorksheetFunction.Combin(49, 6). The same name can be used to create a function in VBA with no conflict.

Function for calculating Combinations without replacement: -

Function CombinWoR(n As Byte, k As Byte) As Double
  ' n = Pool; k = Pick; n must be >= k; m must be between 0 and n 
    Dim i as Byte

    Dim cv As Double

     cv = n

     If n >= k AND n <101 Then

         For i = 1 to k - 1

              cv = cv * (n-i)

         Next i

          cv = cv/Factorial(k)

         Else CombinWoR = 0

     End If

     CombinWoR = cv

       'Following works for smaller values

      'CombinWoR = Fct(n) / Fct(k) / Fct(n - k)

End Function

Procedure for enumerating Combinations without repetition:

Public Sub EnumCombWoR(Pl As Byte, Pk As Byte)

Dim cnt As Long
Dim ary() As Byte
Dim a As Byte,  b As Byte, c As Byte, d As Byte, e As Byte, f As Byte
Dim Elements As Long
Elements = CombinWoR(Pl, Pk)

Select Case Pk      'If Pl 49 and Pk 6 then cnt is 13,983,816
  Case 6

       ReDim ary(1 To Elements, 1 To 6)


      For a = 1 To Pl - 5
        For b = a + 1 To Pl - 4
          For c = b + 1 To Pl - 3
            For d = c + 1 To Pl - 2
              For e = d + 1 To Pl - 1
                For f = e + 1 To Pl

                      cnt = cnt + 1                      

                      ary(cnt, 1) = a
                      ary(cnt, 2) = b
                      ary(cnt, 3) = c
                      ary(cnt, 4) = d
                      ary(cnt, 5) = e
                      ary(cnt, 6) = f
                      'Debug.Print a & vbTab & b & vbTab & c & vbTab _
                                & d & vbTab & e & vbTab & f

                  Next f
                Next e
              Next d
            Next c
          Next b
        Next a

      Debug.Print "Count of combinations in array: " & cnt
      Debug.Print "Value of element 13983816 in array: " & _
      ary(13983816, 1) & vbTab & ary(13983816, 2) & vbTab & ary(13983816, 3) _
      & vbTab & ary(13983816, 4) & vbTab & ary(13983816, 5) _ 

& vbTab & ary(13983816, 6)         
   
     Case 3    'For Pl 10 (0 to 9) cnt is 120 ie unmatched 120 x 6 = 720 as in Pick 3

      ReDim ary(1 To Elements, 1 To 3)  

 

          For a = 0 To Pl - 3
              For b = a + 1 To Pl - 2
                For c = b + 1 To Pl - 1
                      cnt = cnt + 1
                      ary(cnt, 1) = a
                      ary(cnt, 2) = b
                      ary(cnt, 3) = c
                     

                     'Debug.Print a & vbTab & b & vbTab & c

            Next c
          Next b
        Next a


      Debug.Print "Count of combinations in array: " & cnt
      Debug.Print "Value of element 720 in array: " & _
      ary(720, 1) & vbTab & ary(720, 2) & vbTab & ary(720, 3)      
   

End Select
            
 

End Sub

 

 

Combinations with Repetition or Replacement: -

 

Function for calculating Combinations with replacement: -

 

Function CombinWR(n As Byte, k As Byte) As Long
  ' n = Pool; k = Pick; n must be >= k; m must be between 0 and n 
    If n >= k Then
        CombinWR = Fct(n + k - 1) / (Fct(k) * Fct(n - 1))
    Else
        CombinWR = 0
    End If
End Function

 

Procedure for enumerating Combinations without Repetition or Replacement: -

 

Public Sub EnumCombWR(Pl As Byte, Pk As Byte)

Dim cnt As Long
Dim a As Byte, b As Byte, c As Byte, d As Byte, e As Byte, f As Byte

 

Select Case Pk                                        'Pl 49 and Pk 6 then cnt is 25,827,165
  Case 6
      For a = 1 To Pl
        For b = a To Pl
          For c = b To Pl
            For d = c To Pl
              For e = d To Pl
                  For f = e To Pl

                      cnt = cnt + 1
                      'Debug.Print a & vbTab & b & vbTab & c & vbTab _
                                & d & vbTab & e & vbTab & f

                  Next f
                Next e
              Next d
            Next c
          Next b
        Next a
         
    Case 3                              'For Pl 10 (0 to 9) cnt is 220
            For a = 0 To Pl - 1
              For b = a To Pl - 1
                For c = b To Pl - 1
                      cnt = cnt + 1
                      'Debug.Print a & vbTab & b & vbTab & c

            Next c
          Next b
        Next a
     

     End Select    
      
      Debug.Print cnt

 

End Sub

 

Calculating the Odds for the Prizes

The code for calculating the Prize Odds is easily done now that the functions as detailed above are available to apply to the formulae. Taking a 6/49 Lotto game as an example the odds would be given by the following -

 

    lblPrizeThree.Caption = "1 in " & Format(CombinWoR(Pl, Pk) / (CombinWoR(Pk, 3) * IIf(CombinWoR((Pl - Pk), 3) = 0, 1, CombinWoR((Pl - Pk), 3))) / tbxTickets.Value, "##,##0.00")


    lblPrizeFour.Caption = "1 in " & Format(CombinWoR(Pl, Pk) / (CombinWoR(Pk, 4) * IIf(CombinWoR((Pl - Pk), 4) = 0, 1, CombinWoR((Pl - Pk), 2))) / tbxTickets.Value, "##,##0.00")


    lblPrizeFive.Caption = "1 in " & Format(CombinWoR(Pl, Pk) / (CombinWoR(Pk, 5) * IIf(CombinWoR((Pl - Pk), 5) = 0, 1, CombinWoR((Pl - Pk), 1))) / tbxTickets.Value, "##,##0.00")


    lblPrizeSix.Caption = "1 in " & Format(CombinWoR(Pl, Pk) / (CombinWoR(Pk, 6) * IIf(CombinWoR((Pl - Pk), 6) = 0, 1, CombinWoR((Pl - Pk), 0))) / tbxTickets.Value, "##,##0")

 

Providing an Excel User-Form Interface

For Access or Visual Basic the natural interface is a form. In Excel a better choice than using controls on a worksheet when spreadsheet features are not needed, is a UserForm as shown below: -

 
 

 
 
Colin Fairbrother
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.