how do I fix the seed in the trnd function

조회 수: 2 (최근 30일)
Sabbas
Sabbas 2012년 11월 10일
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

채택된 답변

Wayne King
Wayne King 2012년 11월 10일
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
Sabbas
Sabbas 2012년 11월 10일
편집: Sabbas 2012년 11월 10일
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 2012년 11월 10일
I get the following
rand('state',30)
x = rand(10,1)
%%%now using rng
rng(30,'v5uniform')
y = rand(10,1)
Identical

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 11월 10일
Use the rng() function before you call trnd()
  댓글 수: 2
Sabbas
Sabbas 2012년 11월 10일
편집: Sabbas 2012년 11월 10일
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 2012년 11월 10일
could someone help?
thanks

댓글을 달려면 로그인하십시오.


Wayne King
Wayne King 2012년 11월 10일
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
Sabbas
Sabbas 2012년 11월 10일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by