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
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’)
% xlow= lowest integer allowed
% xhigh = highest integer allowed
% number of integers to be picked
% numbers to be skipped
lottoskip=[ 2 5 7 12 21];
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’)
% 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.
% number of lotto numbers to be skipped from being chosen
% 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
% checking against previous numbers chosen
% checking against numbers to be skipped
disp(‘The lotto numbers picked are’)
disp (‘ ‘)
This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com.