lotto.m

来自「其中提到遺傳學的程式碼與應用提供給次淚相向的研究者參考下載」· M 代码 · 共 43 行

M
43
字号
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 + =
减小字号Ctrl + -
显示快捷键?