⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 casino.m

📁 一些常被用于教学或者参考的概率论的实例的源代码
💻 M
字号:
%casino.m/created by PJNahin for "Duelling Idiots"(12/27/98)
%This m-file simulates 10,000 games of "Chuck-a-Luck" and
%calculates the average winnings. That is, you bet $1 each
%game and the winnings (W) are how much MORE money you have
%over and above the $10,000 betting money. The average
%winnings are, of course, W/10,000.
%
%
rand('state',100*sum(clock))       %new seed for generator;
W=0;                               %initialize total winnings;
for games=1:10000                  %play 10,000 games;
   bet=floor(6*rand)+1;            %pick an integer from 1 to 6;
   for roll=1:3                    %roll three dice
      die1=floor(6*rand)+1;        %and determine
      die2=floor(6*rand)+1;        %what face shows
      die3=floor(6*rand)+1;        %on each;
   end
   matches=0;                      %initialize number of dice
                                   %that match your number;
   if bet==die1
      matches=matches+1;
   end
   if bet==die2
      matches=matches+1;
   end
   if bet==die3
      matches=matches+1;
   end
   if matches==0                   %if no matches, you
      W=W-1;                       %lose your $1 bet,
   else                            %but with matches you
      W=W+matches;                 %win;
   end
end
W=W/10000;
disp(['Average winnings per game is ',num2str(W),' dollars'])

                                      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -