------------------------------------------------------------------------- function x = rndgenm(n,options) %RNDGENM Uniformly distributed random numbers generator. % X = rndgenm(N,OPTIONS) % where N is number of random variates needed, and OPTIONS give a % tap sequence for Linear Feedback Shift Register (LFSR).A default % choose of OPTIONS is [32,7,5,3,2,1,0]. % % RNDGENM produces pseudo-random numbers. The sequence of numbers % generated is determined by the state of the generator. RNDGENM use % Linear Feedback Shift Register (LFSR) to generate a m-sequence. % % See also RAND, RNDGEN
if nargin>2 error('Too many arguments! '); end if nargin<1 error('Requires at least one input argument.'); end if nargin==1 options = [32,7,5,3,2,1,0]; end
options = options(find(options>0)); Len = max(options); if Len>51 | Len<1 error('Tap sequence should be more than 1 and less than 51.'); end
x = []; MAXVAL = 2^Len-1; Register = 0; while Register==0 Register = fix(rand(1)*MAXVAL); end for i = 1:n Feedback = 0; for j = 1:length(options) Feedback = bitget(Register,options(j))+Feedback; end Register = bitshift(Register,-1); Register = bitset(Register,Len,bitget(Feedback,1)); x(i) = Register/MAXVAL; end 作者: bob007 时间: 2005-11-8 11:02
这么强的文章,顶一下!!作者: boyfly 时间: 2005-11-15 08:37
请教我怎么看不到原文,只能看到回复亚作者: vincent 时间: 2005-11-15 09:28