|
"Ulf Graewe" <graewe@icbm.de.skip.this> wrote in message
news:h1aide$bek$1@fred.mathworks.com...
> you can something like this
>
> function [Msgsize] = sizetext(number,key)
>
> if ~isemptey(key)
> rand('state',key)
> endif
> number = 300 * 15;
> Msgsize= round(rand(floor(number),1));
> Msgsize= randintrlv(Msgsize);
>
> by using the rand('state',number) command, you can set the generator to a
> certain state and thus get the same sequence of random numbers.
>
> simply try in the command line
>
> rand('state',1000),rand,rand
>
> rand('state',1000),rand,rand('state',1000), rand
>
> and see the difference!
>
> doc rand gives more information
Since the introduction of the RandStream random number generator
infrastructure, we recommend using RandStream methods and properties to
control the random number generators, rather than the rand(keyword, ...)
syntax. Doing so allows you to isolate your own random number generator
streams, so that your random number generation will not affect others that
are using RandStream generators and their random number generation will not
affect yours. In addition, if you have RandStream available, you will also
have the RANDI function/method available, which can directly generate
integer values. This means you won't need to do ROUND/CEIL/FLOOR/FIX of a
scaled call to RAND.
function msgsize = sizetext(number, key)
mygenerator = RandStream.create('mt19937ar', 'Seed', key);
numElements = 300*15;
% Generate a numElements-by-1 matrix of integers between 0 and 1 inclusive
% using the generator object I created above.
% mt19937ar is the Mersenne Twister algorithm. For a list of other
algorithms
% that are available, see:
%
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.list.html
msgsize = randi(mygenerator, [0 1], numElements, 1)
msgsize = randintrlv(msgsize);
--
Steve Lord
slord@mathworks.com
|