In a previous post, a reader wanted a program that would skip some numbers that he thinks would presumably not show up because they were picked in the previous week’s lotto. Although the probability of the same numbers being picked is the same, human psychology and the lack of true randomness is a viable factor in writing such a program. So here it is where you can input what numbers you do not want to see picked up by the program.

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.

%% PICKING THE LOTTO NUMBERS WHILE SKIPPING SOME

% 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, while numbers asked to be skipped are not chosen

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, while numbers asked to be skipped are not chosen’)

disp(‘ ‘)

%% INPUTS

% xlow= lowest integer allowed

xlow=1;

% xhigh = highest integer allowed

xhigh=53;

% number of integers to be picked

m=6;

% numbers to be skipped

lottoskip=[ 2 5 7 12 21];

disp (‘INPUTS’)

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

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

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

disp(‘Lotto numbers skipped’)

lottoskip

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

% number of lotto numbers to be skipped from being chosen

mskip=length(lottoskip);

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

% also it checks if the numbers asked to skipped are

% not chosen

flag=0;

% checking against previous numbers chosen

for j=1:1:i-1

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

flag=1;

end

end

% checking against numbers to be skipped

for j=1:1:mskip

if (lottonum(i)==lottoskip(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**.

i want good teaching on the skipping of numbers.

LikeLike