473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Number Combinations

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
5 5936
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
13
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number...
20
by: William Stacey [MVP] | last post by:
int list = {1,2,3,4,5,6}; Function to randomize the list? Cheers! -- William Stacey, MVP
2
by: GrantMagic | last post by:
I have found that some strange combinations of characters in a URL can cause an error in my ASP.NET application. This is regarding URL Paramters For example: if i have the URL:...
4
by: Suzie1986 | last post by:
Hiya, I am a newcomer to programming and really stuck!!! Any help would be gratefully received!! I have written a program that gives me all possible combinations for 1 and 2 for a length of...
22
by: MLH | last post by:
If 3 things can be in one of 2 states, the number of possible combinations is equal to 2^3. But if I have 3 things, 2 of which can be in 2 states and the other in 3 states, what's the simplest...
0
by: John Doe77 | last post by:
Hi, Given a phone number I need to print out all the word representation combinations possible from that phone number. Digits translate into chars like the following: 1 = 1 2 = A B C 3 = D E...
1
by: sotirios | last post by:
I have a Table (Table01)in Access with one number field name Num (double) I want a routine to create a new table example Table02 with 2 fields the first with combinations of the numbers of Table01...
6
by: nullgraph | last post by:
Hi everyone, I'm new to Python and the notion of lambda, and I'm trying to write a function that would have a varying number of nested for loops depending on parameter n. This just smells like a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.