randmcg.m
来自「有趣的可视的数值方法 出自网站http://www.mathworks.com」· M 代码 · 共 32 行
M
32 行
function r = randmcg(p,q)%RANDMCG Multiplicative congruential uniform random number generator.% Based on the parameters used by MATLAB version 4.% The statement% r = randmcg% generates a single uniformly distributed random number.% The statement% r = randmcg(m,n)% generates an m-by-n random matrix.% The statement% clear randmcg% will cause the generator to reinitialize itself.% The function can not accept any other starting seed.%% See also RANDGUI, RANDSSP.persistent m a c xif isempty(x) m = 2^31-1; a = 7^5; c = 0; x = 1;endif nargin < 1, p = 1; endif nargin < 2, q = p; endr = zeros(p,q);for k = 1:p*q x = rem(a*x + c, m); r(k) = x/m;end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?