function [out] = dice_simulation()
% 骰子模拟
global iseed
if isempty(iseed)
seed(1024);
end
random_val = random0(1);
for k = 1:6
if random_val >= (k-1)/6 && random_val < k/6
out = k;
end
end
end
function ran = random0 (m, n)
% Script file:random0.m
%
% Purpose:
% Random0 generate uniform random numbers in [0,1)
% Function random0 generates an array of uniform
% random numbers in the range[0,1).The usage is:
%
% random0 (m) -- generate an m x m array
% random0 (n,n) -- generate an m x n array
%
% Define variables:
% ii -- Index variable
% iseed -- Random number seed (global)
% jj -- Index variable
% m -- number of colunms
% msg -- error message
% n -- number of rows
% ran -- output array
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========= ======
matlab 代码(骰子模拟 from matlab programming 4th edittion)
最新推荐文章于 2024-05-07 17:57:21 发布