By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,054 Members | 1,635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,054 IT Pros & Developers. It's quick & easy.

Number Combinations

P: n/a
Hi all I have a theory for a lotto system and need help on how to code
it.

I want to create 1 massive database with EVERY combination of numbers
possible in a given lotto system, then remove all the numbers in a
sequence.

For example, in Australia our lotto system has 45 balls and you need
to pick 6 numbers to win the jackpot.

Using Excel's =combin(45,6) formula, I can work out that there are
8145060 six number combinations. If I remove ALL the numbers that are
in sequence ie 1,2,3,4,5,6 or 10,11,12,13,14,15,16 as examples, how
many combinations do I have left.

I then want to remove all of the past draws (I can do this manually).

How would I go about doing this??

ANY suggestions or a point in the right direction would be greatly
appreciated.

Thanks

Jul 17 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Bails,

8154060 - 40 = 8154020

This really wont help you (much). Removing existing combinations from
the event space is also not going to help much since the number of
draws that have taken place is tiny compared to the number of possible
outcomes.

The reason that such a large event space is used is due to the fact
the the probability of any given number combination is extremely low.
This keeps ticket prices down and makes the game more affordable for
everyday punters. The fact that you see 1st Division prizes being won
is simply due to the sheer number of entries each week. OZ has just
hit the 21 million population mark. You have approximately 8 million
possible ball combinations. 12 combinations per ticket. This means
that you need only 679,505 tickets filled in (minimum with unique
entries) to cover all possible combinations.Thats a fairly small
percentage of the population considering the number of people who
actually play each week, and lodge multiple tickets.

Long story short: Tattersalls worked out the probabilities a long time
ago, and have balanced the odds against the number of people playing
the game so that the probable return of winnings keeps the punters
interested. If they were to pump it up to 6 from 49 there would be too
few winners and people would lose interest. 6 from 49 is used in
Europe a lot because of the population size (more tickets, more
chances).

There really is no way of increasing your chances for this type of
system. You cant really predict randomness except to say that it is
going to be random! If there is a flaw in the system it would be with
the mechanical build of the machine or the balls. You may find
behavioural inconsistencies with the machine such as a particular ball
is more or less likely to come up in a given week based on its past
history. You might want to look into Llambda distributions or
something similar to gauge that sort of thing (compare theory with
actual values for example). I would suggest though that the
Tattersalls group also check for this type of thing and would do
things like rotate the ball sets each week and use different machines
periodically too - kind of like the roulette wheels at the Casino.

Anyway, I wrote a combination 'spinner / calculator' for giving all
possible combinations. It is useful for playing with statistical
models. I will dig it up and post it here next week for you. It might
be in java or C but I will convert it to VBA for you. On rough
calculation, if you use Byte as the field type, you will end up with
something like 120 to 130 mb database for a 6 from 45 combination.

I will try and post it for you monday.

Cheers

The Frog

Jul 20 '07 #2

P: n/a
Hi Bails,

This is some code I wrote a long time ago in MS Access. It is a
function that creates all combinations of n objects from m objects and
places them into a table using classic ADO. It also returns the total
to the whatever called the function.

You would need to update this a bit if you want to use .Net, as the
ADO is quite different. Anyway, it should give you the logic needed to
solve your problem. You could always just run it in MS Access too....

Function Spin(n As Byte, m As Byte, ByRef rs As ADODB.Recordset) As
Long

Dim base() As Byte
Dim limit() As Byte
Dim Terminate As Boolean
Dim increment As Byte
Dim total As Long

ReDim base(n)
ReDim limit(n)

For i = 1 To n
base(i) = i
Next i

counter = m
For i = n To 1 Step -1
limit(i) = counter
counter = counter - 1
Next i

Do While Terminate = False
increment = 0
total = total + 1

rs.AddNew
For i = 1 To n
With rs.Fields
snarf$ = "Ball" & i
.Item(snarf) = base(i)
End With
Next
rs.Update

For i = 1 To n
If base(i) = limit(i) Then
increment = increment + 1
End If
Next

If increment = n Then
Terminate = True
ElseIf increment 0 Then
base(n - increment) = base(n - increment) + 1
For i = (n - increment + 1) To n
base(i) = base(i - 1) + 1
Next
Else
base(n) = base(n) + 1
End If
Loop
Spin = total
End Function

Enjoy, and good luck. If you manage to win at lotto then buy me a beer
next time I'm in Aus :-)

Cheers

The Frog

Jul 23 '07 #3

P: n/a
On Jul 23, 5:33 pm, The Frog <Mr.Frog.to....@googlemail.comwrote:
Hi Bails,

This is some code I wrote a long time ago in MS Access. It is a
function that creates all combinations of n objects from m objects and
places them into a table using classic ADO. It also returns the total
to the whatever called the function.

You would need to update this a bit if you want to use .Net, as the
ADO is quite different. Anyway, it should give you the logic needed to
solve your problem. You could always just run it in MS Access too....

Function Spin(n As Byte, m As Byte, ByRef rs As ADODB.Recordset) As
Long

Dim base() As Byte
Dim limit() As Byte
Dim Terminate As Boolean
Dim increment As Byte
Dim total As Long

ReDim base(n)
ReDim limit(n)

For i = 1 To n
base(i) = i
Next i

counter = m
For i = n To 1 Step -1
limit(i) = counter
counter = counter - 1
Next i

Do While Terminate = False
increment = 0
total = total + 1

rs.AddNew
For i = 1 To n
With rs.Fields
snarf$ = "Ball" & i
.Item(snarf) = base(i)
End With
Next
rs.Update

For i = 1 To n
If base(i) = limit(i) Then
increment = increment + 1
End If
Next

If increment = n Then
Terminate = True
ElseIf increment 0 Then
base(n - increment) = base(n - increment) + 1
For i = (n - increment + 1) To n
base(i) = base(i - 1) + 1
Next
Else
base(n) = base(n) + 1
End If
Loop
Spin = total
End Function

Enjoy, and good luck. If you manage to win at lotto then buy me a beer
next time I'm in Aus :-)

Cheers

The Frog
Thanks Frog, if I actually do win anything substantial, I'll buy you
more than a beer - lol.
Now for another DUMB question!!!!!!

I havent used access in a long time, where should I actually place the
code?? I tried adding it to a command button on a user form but only
get errors. Im using MS Access 2003 with SP2.

Cheers

Jul 27 '07 #4

P: n/a
On Jul 27, 10:07 am, Bails <andrewgbail...@gmail.comwrote:
On Jul 23, 5:33 pm, The Frog <Mr.Frog.to....@googlemail.comwrote:


Hi Bails,
This is some code I wrote a long time ago in MS Access. It is a
function that creates all combinations of n objects from m objects and
places them into a table using classic ADO. It also returns the total
to the whatever called the function.
You would need to update this a bit if you want to use .Net, as the
ADO is quite different. Anyway, it should give you the logic needed to
solve your problem. You could always just run it in MS Access too....
Function Spin(n As Byte, m As Byte, ByRef rs As ADODB.Recordset) As
Long
Dim base() As Byte
Dim limit() As Byte
Dim Terminate As Boolean
Dim increment As Byte
Dim total As Long
ReDim base(n)
ReDim limit(n)
For i = 1 To n
base(i) = i
Next i
counter = m
For i = n To 1 Step -1
limit(i) = counter
counter = counter - 1
Next i
Do While Terminate = False
increment = 0
total = total + 1
rs.AddNew
For i = 1 To n
With rs.Fields
snarf$ = "Ball" & i
.Item(snarf) = base(i)
End With
Next
rs.Update
For i = 1 To n
If base(i) = limit(i) Then
increment = increment + 1
End If
Next
If increment = n Then
Terminate = True
ElseIf increment 0 Then
base(n - increment) = base(n - increment) + 1
For i = (n - increment + 1) To n
base(i) = base(i - 1) + 1
Next
Else
base(n) = base(n) + 1
End If
Loop
Spin = total
End Function
Enjoy, and good luck. If you manage to win at lotto then buy me a beer
next time I'm in Aus :-)
Cheers
The Frog

Thanks Frog, if I actually do win anything substantial, I'll buy you
more than a beer - lol.
Now for another DUMB question!!!!!!

I havent used access in a long time, where should I actually place the
code?? I tried adding it to a command button on a user form but only
get errors. Im using MS Access 2003 with SP2.

Cheers- Hide quoted text -

- Show quoted text -
Hi, someone suggested to generate ALL the combinations that I use 6
for next loops and check for duplicates. I thought that sounded
simple, but I cant seem get it right. I have posted the code below, if
anyone can tell me what I am doing wrong I would appreciate it. Ignore
the timer code, I was just checking to see how long it takes to
generate the numbers.

I used a text box to input the number of balls (ultimately it will be
45), but as it takes Sooooooooo long to process, I thought this would
be easier so that I could test with a smaller number say 10 - even
this takes a while so I might need to streamline the code to do 45.

Anyway here it is - any help would be greatly appreciated..........

Public Class Form1
Dim nCount As Integer
Dim startTime As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
startTime = DateTime.Now()
'Me.Text = "Click to Stop"
Timer1.Start()
'Dim nCount As Long
Dim N1 As Long
Dim N2 As Long
Dim N3 As Long
Dim N4 As Long
Dim N5 As Long
Dim N6 As Long
ListBox1.Items.Clear()
nCount = Int(Val(TextBox1.Text))
If nCount < 6 Then nCount = 6

For N1 = 1 To nCount

For N2 = 1 To nCount
If N2 = N1 Then N2 = N2 + 1
If N2 >= nCount Then N2 = nCount

For N3 = 1 To nCount
If N3 = N2 Or N3 = N1 Then N3 = N2 + 1
If N3 >= nCount Then N3 = nCount

For N4 = 1 To nCount
If N4 = N3 Or N4 = N2 Or N4 = N1 Then N4 = N3
+ 1
If N4 >= nCount Then N4 = nCount

For N5 = 1 To nCount
If N5 = N4 Or N5 = N3 Or N5 = N2 Or N5 =
N1 Then N5 = N4 + 1
If N5 >= nCount Then N5 = nCount

For N6 = 1 To nCount
If N6 = N5 Or N6 = N4 Or N6 = N3 Or N6
= N2 Or N6 = N1 Then N6 = N5 + 1
If N6 >= nCount Then N6 = nCount
Application.DoEvents()
ListBox1.Items.Add(N1 & ", " & N2 & ",
" & N3 & ", " & N4 & ", " & N5 & ", " & N6)
Next
Next
Next
Next
Next
Next

Timer1.Stop()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
Label31.Text = span.Minutes.ToString & ":" & _
span.Seconds.ToString & "." & span.Milliseconds
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Exit Sub
End Sub

Jul 27 '07 #5

P: n/a
On Jul 23, 5:33 pm, The Frog <Mr.Frog.to....@googlemail.comwrote:
HiBails,

This is some code I wrote a long time ago in MS Access. It is a
function that creates all combinations of n objects from m objects and
places them into a table using classic ADO. It also returns the total
to the whatever called the function.

You would need to update this a bit if you want to use .Net, as the
ADO is quite different. Anyway, it should give you the logic needed to
solve your problem. You could always just run it in MS Access too....

Function Spin(n As Byte, m As Byte, ByRef rs As ADODB.Recordset) As
Long

Dim base() As Byte
Dim limit() As Byte
Dim Terminate As Boolean
Dim increment As Byte
Dim total As Long

ReDim base(n)
ReDim limit(n)

For i = 1 To n
base(i) = i
Next i

counter = m
For i = n To 1 Step -1
limit(i) = counter
counter = counter - 1
Next i

Do While Terminate = False
increment = 0
total = total + 1

rs.AddNew
For i = 1 To n
With rs.Fields
snarf$ = "Ball" & i
.Item(snarf) = base(i)
End With
Next
rs.Update

For i = 1 To n
If base(i) = limit(i) Then
increment = increment + 1
End If
Next

If increment = n Then
Terminate = True
ElseIf increment 0 Then
base(n - increment) = base(n - increment) + 1
For i = (n - increment + 1) To n
base(i) = base(i - 1) + 1
Next
Else
base(n) = base(n) + 1
End If
Loop
Spin = total
End Function

Enjoy, and good luck. If you manage to win at lotto then buy me a beer
next time I'm in Aus :-)

Cheers

The Frog
Frog, I put your Function in a Module in access, and a command button
on a form, but cant seem to get the Spin function to fire.

I have used Access before, but never "Function" or Modules so am not
sure how to call tem.

Where am I going wrong??!!

Bails

Aug 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.