![]() |
【求助】关于rand()的使用
rand('state',2);
pn1=rand(1,10); pn2=rand(1,10); 上面的pn1和pn2为什么不一样?不是初始的seeds是2吗? 还有rand具体是怎么实现的? |
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相乘即可! |
所有时间均为北京时间。现在的时间是 12:33。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.