You are on page 1of 11

Forum Question Forums Excel Questions Analyze Lottery Numbers in Excel

Ad by costmin. More Info


Become a Registered Member (free) to remove the ad that appears in the top post.
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can
post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the
selection below.
Click here to reset your password. You MUST have a valid e-mail address so that you may receive the instructions to
complete the reset.
Analyze Lottery Numbers in Excel
This is a discussion on Analyze Lottery Numbers in Excel within the Excel Questions forums, part of the Question
Forums category; Hey all ... my first post here ... I thought this would be a good place to start in order ...

Register
Search New Posts Zero Reply Posts Subscribed Threads MrExcel Consulting
FAQ Forum Actions Quick Links Advanced Search
Results 1 to 10 of 48 Page 1 of 5 1 2 3 ... Last
1Likes
www.cricketcountry.c...
Latest Cricket Updates
TopTipsNews
Top 5 investments for
your money
TopTipsNews
Top 10
Non-Governmental
Organizations
worldwide
BWNToday
14-year-old girl steals
her mother's husband
Forum
You might enjoy reading
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
1 of 11 6/3/2014 6:53 PM
www.shaadi.com
Find Love, arranged by
Shaadi.com
TopTipsNews
Top 10 cities to visit in
the US
LinkBack Thread Tools Display
Sep 6th, 2012, 01:01 PM
Analyze Lottery Numbers in Excel
Hey all ... my first post
here ... I thought this
would be a good place
to start in order to
clarify my
understanding of some
of the content re:
Analyze Lottery
Numbers in Excel
at: Win the Lottery
with Excel
I am motivated by both
the immediate desire to
come up with different
ways of picking lottery
numbers, as well as a
desire to learn more
about Excel (FYI - I'm
still plunking along with
Excel 2000 [9.0.8960
SP-3]) in the process -
this seems like an
excellent endeavor to
do both.
Right out of the gate,
from the above
referenced page, I
think I need
clarification with:
"I downloaded data
from the Ontario lottery
site showing winning
numbers for the past 3
months.
Using cut and paste,
copy the numbers into
a single column of
data. Add a heading in
cell A1.
"
#1
Join Date:
Posts:
Sep 2012
5
K_McIntosh
New Member
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
2 of 11 6/3/2014 6:53 PM
At first read, this
appears to work for
one column of data at a
time ... is it possible to
do all six relevant
(primary data) columns
at once? ie. can we
literally C & P all six
columns worth of data
into one single column
of data ... I wouldn't
have thought so ...
If we're only able to
examine the frequency
of a given integer being
drawn on a column by
column basis (ie. 1st #
drawn, 2nd # drawn,
ect.), my thought is
that we are not seeing
the frequency (or lack
thereof) of partial or
complete strings of six
integers, as drawn
historically. Or the
order in which they
occur, if and when they
do. Apologies - it
seems to me I had this
latter thought
expressed more clearly
yesterday when I first
composed this thread,
however, that portion
was lost due being
auto-logged out and is
just not coming to me
as easily today, for
whatever reason.
When implementing the
=RANDBETWEEN
function (as
'=RANDBETWEEN(1,49
)'), is it possible to
configure the formula
to select six unique
integers at a time? I
tried dragging the
formula from one cell
across six columns and
found that it was
occasionally possible
for one (or more,
although I have yet to
see this) of the six
integers to be
duplicates.
Thanks for any help
offered ... K_McIntosh
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
3 of 11 6/3/2014 6:53 PM
Share
Reply With Quote
Sep 6th, 2012, 10:49 PM
Re: Analyze Lottery Numbers in Excel
I don't believe you can copy them all at once. You have to do one
column at a time. Randbetween cannot be guaranteed to not select
the same number. I think the point is that in lotteries it never
matters if a number is drawn first, second, third ... etc. since they
are always "sorted" into ascending order for the purposes of
reporting the result - so a number drawn is a number drawn. If you
think you can predict lottery results this way you need to take STAT
101 at your local community college ASAP.
#2
Join Date:
Location:
Posts:
Mar 2007
Clev. OH, USA
14,030
xenou
MrExcel MVP
Moderator
Using: Office 2007/Win7 (work) Office 2010/Win7 (home)
You are rich in proportion to the number of things you can let alone.
-- Henry David Thoreau
Share
Reply With Quote
Sep 6th, 2012, 11:15 PM
Re: Analyze Lottery Numbers in Excel
For what it's worth, a lottery number function:
Code:
Function RandomLotteryNumber(ByVal minValue As Long, maxValue As Long, dig
Dim dic As Object '//Scripting.Dictionary
Dim x As Long
Dim a, i
Set dic = CreateObject("Scripting.Dictionary")

Randomize
Do While dic.Count < digits
x = Int((maxValue - minValue + 1) * Rnd + minValue)
If Not dic.Exists(CStr(x)) Then
dic.Add CStr(x), x
End If
Loop

a = dic.Keys
For i = 0 To UBound(a)
a(i) = CLng(a(i))
Next i
Call BubbleSort(a)

RandomLotteryNumber = Join(a, "|")
End Function
Sub BubbleSort(ByRef arr)

Dim First As Long
Dim Last As Long
Dim i As Long, j As Long
Dim Temp As Long

Edit:
called as (in this case) =RandomLotteryNumber(1,49,6)
#3
Join Date:
Location:
Posts:
Mar 2007
Clev. OH, USA
14,030
xenou
MrExcel MVP
Moderator
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
4 of 11 6/3/2014 6:53 PM
meaning, a lottery with six numbers, with the numbers between 1
and 49 inclusive.
Ad by costmin.
Last edited by xenou; Sep 7th, 2012 at 12:20 AM.
Using: Office 2007/Win7 (work) Office 2010/Win7 (home)
You are rich in proportion to the number of things you can let alone.
-- Henry David Thoreau
Share
Reply With Quote
Sep 7th, 2012, 07:14 AM
#4
Join Date:
Posts:
Nov 2010
2,075
mirabeau
Banned user
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
5 of 11 6/3/2014 6:53 PM
Re: Analyze Lottery Numbers in Excel
to generate say 100,000 sets of lottery-type numbers reasonably
quickly, say <3 secs depending on computer, you can try this
Code:
Sub generatelottery()
Const l& = 1 'lower value
Const u& = 49 'upper value
Const n& = 6 'number of numbers per lottery
Dim a() As String, s As String, b() As Boolean
Dim rws&, i&, j&, x&, k&
rws = 10 ^ 5 'number of sets of lottery numbers
ReDim a(1 To rws, 1 To 1)
Randomize
For i = 1 To rws
ReDim b(l To u): k = 0: s = ""
Do
x = Int(Rnd * u) + l
If Not b(x) Then k = k + 1: b(x) = True
Loop Until k = n
For j = l To u
If b(j) Then s = s & "|" & j
Next j
a(i, 1) = Right(s, Len(s) - 1)
Next i
Range("A1").Resize(rws) = a
End Sub
although if you want to analyze the possibilities of shifting lottery
odds in your favor, I doubt that Excel's random generation would be
the same as that of the lottery.
Incidentally, if you do want to analyze sets of 100,000 or 1,000,000
or so, you may find the Pivot Table rather slow.
Share
Reply With Quote
Sep 7th, 2012, 02:41 PM
Re: Analyze Lottery Numbers in Excel
Ad by costmin.
Thanks to all who Replied ... xenou ... your suggestion to take STAT
101 at my local community college ASAP is not lost on me ...
however, this exercise is still a good excuse to learn more about
Excel ...
On that note, would someone here mind pointing me to a practical
Code (as specifically suggested above in the "Code:" windows by
xenou and mirabeau) implementation tutorial on this forum ...
something not too involved that would allow me to move forward in a
#5
Join Date:
Posts:
Sep 2012
5
K_McIntosh
New Member
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
6 of 11 6/3/2014 6:53 PM
practical sense would be best for me for starters ... are we
Record(ing a) New Macro ... or ?
Thanks, K_McIntosh
Share
Reply With Quote
Sep 8th, 2012, 12:17 AM
Re: Analyze Lottery Numbers in Excel
Fair enough.
There have been some recent discussions on learning excel in our
general discussion forum:
How did you guys learn everything?
vba books
Hiker95 has a comprehensive list of online resources in the above
post (several are geared to beginners). Also try googling "Excel VBA
tutorial". Good luck! I learned the hard way - reading books, trying
things, doing things the wrong way, and slowly figuring out better
ways. Some years ago I also found certain members to be very
useful to me - learning from their posts and working out how their
solutions went until I understood how they worked.
#6
Join Date:
Location:
Posts:
Mar 2007
Clev. OH, USA
14,030
xenou
MrExcel MVP
Moderator
Using: Office 2007/Win7 (work) Office 2010/Win7 (home)
You are rich in proportion to the number of things you can let alone.
-- Henry David Thoreau
Share
Reply With Quote
Sep 16th, 2012, 01:15 PM
Re: Analyze Lottery Numbers in Excel
Ad by costmin.
OK guys ... I did some reading and experimenting ...
I've got xenou's Code, called by
'=RandomLotteryNumber(1,49,6)', stored as (a Microsoft Visual
Basic) 'Module1', under 'VBA Project (filename1.xls)' > 'Modules' in a
given Workbook (filename1.xls), however, it is not visible under
'Tools' > 'Macro' > 'Macros' in said Workbook ... is the Code running
by virtue of entering the calling formula nevertheless?
#7
Join Date:
Posts:
Sep 2012
5
K_McIntosh
New Member
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
7 of 11 6/3/2014 6:53 PM
And, I've got mirabeau's Code stored as (a Microsoft Visual Basic)
'Module1', under 'VBA Project (filename2.xls)' > 'Modules' in a given
Workbook (filename2.xls), and, it is visible under 'Tools' > 'Macro' >
'Macros' in said Workbook ... however, when Run, it fails with
"Run-time error '1004': Application-defined or object-defined error"
due to me not having figured out how to integrate this 'visible' Macro
properly into 'filename1.xls'.
Can I get a nudge in the right direction please?
Thanks, K_Mc
Share
Reply With Quote
Sep 16th, 2012, 01:20 PM
Re: Analyze Lottery Numbers in Excel
xenou's code is implemented as a user-defined function, so yes, you
just enter the formula in a cell. It doesn't appear under Tools >
Macros because (a) it's a Function, not a Sub, and (b) it requires
arguments.
#8
Join Date:
Location:
Posts:
May 2008
The Great State of
Texas
13,390
shg
MrExcel MVP
Microsoft MVP - Excel
Share
Reply With Quote
Sep 16th, 2012, 01:41 PM
Re: Analyze Lottery Numbers in Excel
My function does not appear in the macros dialog because it takes
parameters (the values for min, max, digits). Subs or Functions that
takes parameters are "invisible" in this regard. Mirabeau's code is
probably failing you because it returns 100000 rows which is more
than can fit into an xls file (limited to 65536 rows).
This is a bad hack (apologies to mirabeau) to shorten the results (a
more robust fix might put the data in more than one column or on
more than one sheet):
Code:
Sub generatelottery()
Const l& = 1 'lower value
Const u& = 49 'upper value
Const n& = 6 'number of numbers per lottery
Dim a() As String, s As String, b() As Boolean
Dim rws&, i&, j&, x&, k&
rws = 10 ^ 5 'number of sets of lottery numbers
ReDim a(1 To rws, 1 To 1)
Randomize
For i = 1 To rws
ReDim b(l To u): k = 0: s = ""
#9
Join Date:
Location:
Posts:
Mar 2007
Clev. OH, USA
14,030
xenou
MrExcel MVP
Moderator
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
8 of 11 6/3/2014 6:53 PM
Do
x = Int(Rnd * u) + l
If Not b(x) Then k = k + 1: b(x) = True
Loop Until k = n
For j = l To u
If b(j) Then s = s & "|" & j
Next j
a(i, 1) = Right(s, Len(s) - 1)
Next i
If UBound(a, 1) > 65536 Then
For x = 1 To 65536
Cells(x, 1).Value = a(x, 1)
Next x
MsgBox "Results exceed 65536 rows!"
Else
Range("A1").Resize(rws) = a
End If
my code can be used by calling it from a cell in the spreadsheet.
=RandomLotteryNumber(1,49,7)
Which would supply a lottery number of 7 digits, using the numbers
1 to 49. You can also enter this formula by using the formula wizard
on the formulas tab (I have forgotten where it is in Excel 2003 -
maybe it was a button right to the left of where you'd type the
formulas on the formula bar). When you select the formula category
choose UDF (User-Defined) and you should see it.
Here, by the way is an alternate version you could use:
Code:
Function RandomLotteryNumber_Array(ByVal minValue As Long, maxValue
Dim dic As Object '//Scripting.Dictionary
Dim x As Long
Dim a, i
Set dic = CreateObject("Scripting.Dictionary")

Randomize
Do While dic.Count < digits
x = Int((maxValue - minValue + 1) * Rnd + minValue)
If Not dic.Exists(CStr(x)) Then
dic.Add CStr(x), x
End If
Loop

a = dic.Keys
For i = 0 To UBound(a)
a(i) = CLng(a(i))
Next i
Call BubbleSort(a)

RandomLotteryNumber_Array = a

End Function
In this version, you select the cells A1 to G1 (a seven cell range
corresponding to the seven digits of the lottery number, and enter
the formula into cell A1:
=RandomLotteryNumber_Array(1,49,7)
But you must press Control-Shift-Enter, not just enter, to array enter
the formula. Now the seven cells will hold the seven digits.
Last edited by xenou; Sep 16th, 2012 at 01:49 PM.
Using: Office 2007/Win7 (work) Office 2010/Win7 (home)
You are rich in proportion to the number of things you can let alone.
Share
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
9 of 11 6/3/2014 6:53 PM
Previous Thread | Next Thread
-- Henry David Thoreau
Reply With Quote
Sep 16th, 2012, 02:12 PM
Re: Analyze Lottery Numbers in Excel
All sounds overly complicated to me.
I use the following
Code:
Sub euromillions_number_generator()
'
'globally declare variables
'
Dim iloop As Integer
Dim array1() As Variant
Dim array2() As Variant
Dim already_picked() As Boolean
Dim already_picked2() As Boolean
Dim random_number As Long
Dim myRange As Range
Dim low As Long
Dim high As Long
Dim lowx As Long
Dim highx As Long
Dim lshigh As Double
#10
Join Date:
Posts:
Jul 2012
15
chucklesl066
Banned
Share
Reply With Quote
Page 1 of 5 1 2 3 ... Last
Twitter
Linked In
Google
Reddit
StumbleUpon
Like this thread? Share it with others
You may not post new
threads
You may not post replies
You may not post
attachments
You may not edit your posts

Posting Permissions
BB code is On
Smilies are On
[IMG] code is On
[VIDEO] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
10 of 11 6/3/2014 6:53 PM
-- vB4 Default Style
Contact Us Ask Mr. Excel - Tips and Solutions for Excel Privacy Statement Terms of
Service Top
All times are GMT -4. The time now is 09:19 AM.
Powered by vBulletin Version 4.2.0
Copyright 2014 vBulletin Solutions, Inc. All rights reserved.
All contents Copyright 1998-2014 by MrExcel Consulting.
Forum Rules
Analyze Lottery Numbers in Excel http://www.mrexcel.com/forum/excel-questions/657789-analyze-lottery...
11 of 11 6/3/2014 6:53 PM

You might also like