**Tags**

In these tough economic times, more people are playing lotto to hit it big. We have written a MATLAB program that chooses unique and random numbers for a lotto. The inputs are the number of numbers to pick, and the range in which the numbers can be picked.

The MATLAB program can be downloaded as a **Mfile ** (better to download it, as single quotes from the web-post do not translate correctly with the MATLAB editor). The **html** file showing the mfile and the command window output is also available.

Can you modify this program to put the numbers in an ascending order?

How does the random number generator work?

How can I get random numbers that are different every time I run the program?

%% PICKING THE LOTTO NUMBERS

% Language : Matlab 2007a

% Authors : Autar Kaw

% Last Revised : November 10, 2008

% Abstract: This program chooses randomly m unique numbers to play

% the lotto. Lotto numbers allowed are positive integers from

% xlow to xhigh

clc

clear all

disp(‘This program chooses randomly m unique numbers to play’)

disp(‘the lotto. Lotto numbers allowed are positive integers from’)

disp(‘xlow to xhigh’)

disp(‘ ‘)

%% INPUTS

% xlow= lowest integer allowed

xlow=1;

% xhigh = highest integer allowed

xhigh=53;

% number of integers to be picked

m=6;

disp (‘INPUTS’)

fprintf(‘Lowest integer allowed=%g’,xlow)

fprintf(‘\nHighest integer allowed=%g’,xhigh)

fprintf(‘\nNumbers to be picked=%g’,m)

disp(‘ ‘)

% Using the random number generator rand to get the lotto numbers.

% rand generates numbers between 0 and 1. So we multiply that by xhigh-xlow+1

% and shift it by xlow and then floor it to get the integer part.

%% SOLUTION

i=1;

while (i<=m)

lottonum(i)=floor(xlow+rand*(xhigh-xlow+1));

% flag= variable that keeps track of previous numbers

% being same or different from the number picked

flag=0;

for j=1:1:i-1

if (lottonum(i)==lottonum(j))

flag=1;

end

end

if flag==0

i=i+1;

end

end

%% OUTPUT

disp(‘ ‘)

disp(‘OUTPUT’)

disp(‘The lotto numbers picked are’)

fprintf(‘%g ‘,lottonum)

disp (‘ ‘)

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://numericalmethods.eng.usf.edu.

An abridged (for low cost) book on *Numerical Methods with Applications* will be in print (includes problem sets, TOC, index) on December 10, 2008 and available at lulu storefront.

Subscribe to the blog via a reader or email to stay updated with this blog. **Let the information follow you**.

Yo Mismo

said:I think it would be a good idea to add the possibility of removing a set of numbers, that way you can remove last week’s winning combination.

LikeLike

Gordon

said:Picking random numbers each time you play the lottery seems an odd thing to do.

Accoring to Lottery management companies, 80% of the people pick random numbers 20% choose their own and play the same numbers each time.

Which group get better results? Apparently the split is exactly 50/50. So choosing your own numbers and sticking with them seems to be a better option.

Be careful though to choose a set of numbers that have never won before, because the chances of the same set of numbers winning twice, especially with the 5 and 6 picks, is highly improbable as to make it considered impossible.

LikeLike

David Woodford

said:You should be careful picking the same numbers evrey time though because that forces you to play every week. How would you feel if you missed it once and that was the time “your numbers” came up?

Also I’m not sure I follow the reason that you shouldn’t pick numbers that have come up before> I understand it is unlikely that a set of numbers will appear twice but the probability of certain numbers coming up one week is the same whether or not they came up the week before isn’t it.

LikeLike

Pingback: Skipping numbers in picking the lotto numbers « The Numerical Methods Guy

Pingback: Picking Lottery Numbers

Wayne

said:………here’s the deal 🙂

Picking RANDOM NUMBERS is INSANE!!!

Using the frequencies of the most picked numbers, in a certain time of the week, is probably the best you can do to win a lottery!

Wayne

LikeLike

Autar Kaw

said:I do not think there is any science to picking lottery number. Nothing is truly random but all the schemes people come up with choosing lottery numbers are not correct.

LikeLike

Pingback: Bubble sorting « The Numerical Methods Guy

Bridgette Velardes

said:I am having trouble viewing this blog. It displays all funny with text displaying incorrectly. You might want to look at this.

LikeLike

Autar Kaw

said:Try using internet explorer.

LikeLike

ibrahim kaya

said:The numbers evolve and reproduce like the nature, the lotto numbers are also have some forms genetical patterns due to the nature of the system. Thus if you could find out the genetical patterns of the drawings and unless a mutation occurs the system nature forces a condition of survival of the fittest so you have the numbers.

LikeLike

Srikanth

said:Sir,

your commands generate only one lines of 6 numbers

how do I generate more lines ?

pardon me am not familiar with math lab just got it to try my luck.

LikeLike