📄 lotto.m
字号:
function lotto(times)
% LOTTO.m
% This program gives you LOTTO numbers if you ask for the number
% of times.
% times : how many times you want to have the lotto number which
% consists of 6 intgers and 1 extra integer for each time.
% Integers are limited to 1 to 42.
% output: Print out the sequences of lotto numbers on the screen.
% Programmer: PenChen Chou
% Coded on 3/20/2002
% Check input argument number
if nargin==0
times=1;
end
if nargin>1
error('ERROR! Too may parameters you give for calling this function');
end
fprintf('\n');
% for loops for times
for j=1:times
% Set up 42 balls
Ball=1:42;
Numbers=[]; % Store the coming integer up to 7 integers in array
Head=42; % Upper limit of the coming integer
% Throw out 7 intgers
for i=1:7
x=fix(Head*rand-0.001)+1; % Throw out an integer
Numbers=[Numbers Ball(x)]; % Put the xth number into Numbers
Ball(x)=[]; % Clear the given number out of Ball
Head=Head-1; % Decrement Upper limit of thrown integer
end
% Print out the numbers
fprintf(' ');
for i=1:6
fprintf('%3d',Numbers(i));
end
fprintf(' (%2d)',Numbers(7));
fprintf('\n');
end
% Print congradulation message to customers
fprintf('<<< WISH YOU WIN THE GAME !!! >>>\n\n');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -