how do I fix the seed in the trnd function

5 visualizaciones (últimos 30 días)
Sabbas
Sabbas el 10 de Nov. de 2012
Dear all,
I use matlab 2012 and I want to generate values from a student t distribution. I use the function "trnd". HOw can I fix the see in this function
thanks

Respuesta aceptada

Wayne King
Wayne King el 10 de Nov. de 2012
I'm not sure why you want to do that since you can use rng() without using the legacy mode by removing those calls and using rng() instead.
But if you are insisting, then you have to do something like:
rng(sd,'v5uniform')
for calls to rand()
and
rng(sd,'v5normal')
for randn(), where sd is the seed.
You should enter
>>help rng
at the command line and read the documentation linked from
Updating Your Random Number Generator Syntax.
This is all explained there in detail.
  2 comentarios
Sabbas
Sabbas el 10 de Nov. de 2012
Editada: Sabbas el 10 de Nov. de 2012
thank you king.
I tried the following:
initially I had
rand('state',30 );
randn('state',80);
then I did
rng(30,'v5uniform')
rng(80,'v5normal')
but I do not get equivalent results. why?
thanks
Wayne King
Wayne King el 10 de Nov. de 2012
I get the following
rand('state',30)
x = rand(10,1)
%%%now using rng
rng(30,'v5uniform')
y = rand(10,1)
Identical

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 10 de Nov. de 2012
Use the rng() function before you call trnd()
  2 comentarios
Sabbas
Sabbas el 10 de Nov. de 2012
Editada: Sabbas el 10 de Nov. de 2012
you mean for example
rng(1) trnd(7)
because I get this erro message
Error using rng (line 96) The current random number generator is the legacy generator. This is because you have executed a command such as rand('state',0), which activates MATLAB's legacy random number behavior. You may not use RNG to reseed the legacy random number generator.
Use rng('default') to reinitialize the random number generator to its startup configuration, or call RNG using a specific generator type, such as rng(seed,'twister').
JUst to mention that in my code I fix the seed for rand and randn before using rng()
thanks
Sabbas
Sabbas el 10 de Nov. de 2012
could someone help?
thanks

Iniciar sesión para comentar.


Wayne King
Wayne King el 10 de Nov. de 2012
Don't do that. Don't call rand('state', ) before using rng.
rng seeds the random number generator for you. Remove that from and your code and just use rng() to do the work.
  1 comentario
Sabbas
Sabbas el 10 de Nov. de 2012
ok. Is there a way to keep rand('state',) and fix the random seed for trnd at the same time? because ALL my results are based on rand('state', ) and it is very important for me to keep rand('state', ) and randn('state',) . If I do what you say and remove rand('state,) that would be a disaster.
thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by