[s1,s2,s3,s4] = RandStream.create('mrg32k3a','NumStreams',4,'Seed',0);
rn = randn(s1,10,1); % Normal distributions
ru = rand(s2,10,1); % Uniform distributions
ri = randi(s3,100,10,1); % interger uniform
rg = gamrnd(2,1,10,1)
Hello,
Im not sure if I understand your question.... are you trying to set the seed for the gamma ramdom generator number? so anyone can replicate a code? Or you are experiencing problems with the function gamrnd???
trying to set a starting seed so i can get a reproducible sequence every time thru my code
Presumably all you need to do is set some fixed seed you have chosen for either rand or else randn (I don't know which) just prior to generating the sequence of gammarnd quantities to make them repeat the same sequence of values. Of course that presupposes that other differing uses of rand or randn do not intervene during such a generation sequence.
Roger Stafford
Thats right. This will give you the same set of numbers each time.
seed=15;
randn('state',seed)
rand('state',seed)
randg(4,3,1)
Just two things, you need to set randn and rand everytime before using randg. And gamrnd calls randg, so this also apply to gamrnd.
Hi David, Using the Randstream syntax:
% just an example
rs = RandStream.create('mt19937ar','Seed',2007);
% make your stream the default stream
RandStream.setDefaultStream(rs)
R = gamrnd(2,3,10,1)
% use the reset method
reset(RandStream.getDefaultStream)
R = gamrnd(2,3,10,1)
Wayne
"Rogelio " <roge...@math.uio.no> wrote in message
news:i6veel$bli$1...@fred.mathworks.com...
But the syntax you posted does a bit more than you think it does.
http://www.mathworks.com/help/techdoc/math/bsn94u0-1.html
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Unless you are using a version of MATLAB prior to R2008b, I strongly
recommend that you NOT DO THE ABOVE. The syntax above puts you back to
using an old random number generator that is NOT RECOMMENDED.
Roger has it almost right, except that since R2008b, RAND, RANDN, and
RANDI all depend on one stream of random numbers, as described in their
helps. So if you want to repeat random numbers, ALL YOU NEED TO DO IS:
s = RandStream.getDefaultStream;
reset(s);
and then call rand, randn, randi, or any function that depends on them,
which includes all the random number generator functions in the
Statistics Toolbox. You'll get the same thing as if you restarted
MATLAB, assuming that you have not executed a command that changes
MATLAB's global random number stream.
If you want to repeat random numbers, but not the same ones as you get
at MATLAB startup, then do this:
s = RandStream.getDefaultStream;
reset(s,1); % or 2, or 3, or 9172010
[call rand or etc.]
reset(s,1);
[cal rand etc.]
David, you've used a much more complicated scheme where your using a
different stream of random numbers for each distribution. You may have
meant to do that, and it is perfectly valid. If you're really after
something along those lines, I recommend you read these two blog entries:
<http://blogs.mathworks.com/loren/2008/11/05/new-ways-with-random-numbers-part-i/>
<http://blogs.mathworks.com/loren/2008/11/13/new-ways-with-random-numbers-part-ii/>
However, be aware that the RNG functions in the Statistics Toolbox such
as gamrnd do not (yet) support a stream input argument. You'll have to
create your own version for now, such as
function r = mygamrnd(stream,varargin)
oldStream = RandStream.setDefaultStream(stream);
r = gamrnd(varargin{:});
RandStream.setDefaultStream(oldStream);
But again, that is perhaps not what you were really wanting to do. Hope
this helps.
Thanks all
I've tried a bunch of these already and I thought i understood the random number initialization but now i think i need to review it a little more. I am 2009b, which is why i've avoided using the randn('state',seed) method as i'm told it'll no longer be supported. I'll study all these comments, and i've also got a help question into mathworks so if i don't figure it out i should be able to get something from them.
thanks again