Number Combinations

B

Bails

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
 
G

Guest

That is easy, there are a whole 40 of them! The one that starts at 1, the
one that starts at 2 etc. Remember that comb(45,6) already removed the
'permutations' of any 6 numbers. That is the diff caused by ordering has
been removed from the total. Think you need a new theory!
 
A

Andrew Morton

Bails said:
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.

They are not numbers as such, merely labels. There is no significance in any
combination of the labels. Substitute animal names for the numbers and then
tell us why you want to exclude, for example, ungulates.

Andrew
 
B

Bails

They are not numbers as such, merely labels. There is no significance in any
combination of the labels. Substitute animal names for the numbers and then
tell us why you want to exclude, for example, ungulates.

Andrew

To add to what I have said about my theory and it is exactly that a
theory or idea, is that I know there are over 8 million combinations
of numbers, and it is POSSIBLE for each and every one of these
combinations to be drawn, it is highly IMPROBABLE that the sequence,
1,2,3,4,5,6 or any series of 6 CONSECUTIVE numbers will ever be drawn
out.

So if we remove ALL of those sequences we are left with a more
realistic number of combinations. What I want to know is - how many
combinations does this leave.

There are other other factors and sequences I want to remove such as
ALL past drawn numbers as again whilst it is possible for them to come
out, it is highly IMPROBABLE that this will ever happen.

Im sure someone out there will argue this point and probably provide
proof of draws/numbers occuring more than once, but this is the
tiniest minority and one that I can live with in my theory.

Its just an idea I have had that has been bugging me for a while and
now I have to either prove or disprove my idea to myself once and for
all. Havent you ever had an idea that just nags at you until you do
something with it - this is mine.

Cheers
 
T

The Frog

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
 
T

The Frog

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
 
B

Bails

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
 
B

Bails

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
 
B

Bails

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
 
T

The Frog

Hi Bails,

Sorry for the delay, I havent been receiving messages about this
thread for some reason, and one came through today - so....

The way to use that function is as follows:

1/ You need to make a new module (well it can be an existing one but
lets keep things simple for now...)

2/ in that module, lets call it 'Tatts', we copy the function code
that I posted a few posts back.

3/ remove the Option Explicit and Option Compare Database stuff from
the top of the module, I cant remember if I explicitly declared all
the variables or not so its easier for our experiment to just wipe
them out...

4/ Save this module - the function is now available to be used in the
application

5/ Go to tools -> references and select Microsoft ActiveX Data Objects
2.xx (where xx is some number) - This gives the application usage of
the ADO library needed for handling the generated data... (once you
have done this go back and check that it is actually "ticked" and
selected. The function wont work without it.)

The way the function works is to accept parameters for n and m, where
n represents the number of balls you want to take out for any single
draw, and m represents the number of balls that are possible to choose
from.

The function also accepts an ADODB.Recordset object, which is a fancy
way of saying it accepts a table in your database as something it can
work with. In order to give this table to the function we need to
first make the table if it doesnt exist, and then create the adodb
stuff necessary to make that ADODB.Recordset object that the function
needs.

What I suggest is as follows:

- Go to tables
- Create a new table
- Create six columns named "Ball1", "Ball2"......"Ball6"
- Each columns data type should be set to Number, and the field size
set to Byte
- Save the table and give it a meaningful name, maybe 6from45

Okay, we now have all the basic building blocks in place to run this
experiment. As you get better with code you will start to build code
that generates the tables for you and so on, but for now we just did
it by hand because it it more expedient.

We can now write a Sub (routine) that takes values for n and m,
creates all the necessary stuff to connect up the ADODB.Recordset, and
then passes all this to the function to do its job.

There are two ways to do this, one is via a form where you enter the
variables into fields and click a button, but we are going to do the
quick and dirty method because it is really a one time thing for this
experiment.

use the following code to 'Get the balls rolling' (ahem..poor attempt
at humour):

Create a new module, and wipe out the junk at the top
copy in the following code


Sub CrunchTime()

dim Combinations as Long
dim NumberRecords as ADODB.Recordset
dim cn as ADODB.Connection

set cn = CurrentProject.Connection

With NumberRecords
.ActiveConnection = cn
.Source = "6from45" ' - this is the name of the table
.Open
.ActiveConnection = Nothing
End With

Combinations = Spin(6,45,NumberRecords)

NumberRecords.ActiveConnection = cn
NumberRecords.UpdateBatch

NumberRecords.Close
cn.Close

Set NumberRecords = Nothing
Set cn = Nothing

Beep

End Sub

I wrote this code straight into the newsgroup editor here so check it
for typos. Make sure to save the module before running anything.

To make this run all you need to do is to place the cursor on the
first line where the Sub statement is, and click the 'play' button on
the toolbar, or go to the menubar and select run -> run / continue, or
press F5.

I am not sure how long this would take to run, maybe up to an hour or
two - depends on your processor. You would also need to make sure that
the machine you run this on has enough memory to run it. I would guess
that around 128mb to 256mb for the data while it is in memory, so
512Mb of RAM should be enough (I am guessing - you will get an error
if it is not). This routine will also use the processor 100%, so the
less junk running on the machine the faster it will go. I expect that
the whole machine will basically look frozen while this is running, so
go away and have a beer, check back on it a while later.

I hope this gets you where you want to be. You could adapt the code to
do different ball / draw combinations, just make sure you have made
the table for it before running it or it will crash. Likewise dont
forget if you run different combinations you may need much more memory
on the machine, eg/ 6 from 49 would probably blow a gig or two. There
is also a limit on how big an MDB file can be, I think its two gig.

Enjoy, have fun, and let me know how it goes :)

Cheers

The Frog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top