查看单个帖子
旧 2007-08-04, 09:54   #2
linlan999
初级会员
 
注册日期: 2007-08-04
帖子: 5
声望力: 0
linlan999 正向着好的方向发展
默认

rand(method,s) causes rand to use the generator determined by method, and initializes the state of that generator using the value of s.

The value of s is dependent upon which method is selected. If method is set to 'state' or 'twister', then s must be either a scalar integer value from 0 to 2^32-1 or the output of rand(method). If method is set to 'seed', then s must be either a scalar integer value from 0 to 2^31-2 or the output of rand(method).

Input argument method can be any of the strings shown in the table below:
'state'
Use a modified version of Marsaglia's subtract with borrow algorithm (the default in MATLAB versions 5 and later). This method can generate all the double-precision values in the closed interval [2^(-53), 1-2^(-53)]. It theoretically can generate over 2^1492 values before repeating itself.
'seed'
Use a multiplicative congruential algorithm (the default in MATLAB version 4). This method generates double-precision values in the closed interval [1/(2^31-1), 1-1/(2^31-1)], with a period of 2^31-2.
'twister'
Use the Mersenne Twister algorithm by Nishimura and Matsumoto. This method generates double-precision values in the closed interval [2^(-53), 1-2^(-53)], with a period of (2^19937-1)/2.

那个参数seed并不是用来定义随机数的初始值的,而只是作为选择随机数产生器的选项,如果使用了seed参数,就选择了某种算法(也就是随机数产生器)产生随机数。
rand只能产生0-1之间的随机数,要产生其它范围的随机数据可以用一个数与rand相乘即可!
linlan999 当前离线   回复时引用此帖