Can anyone please explain this statement:
rand('state',11) ?!

2 comentarios

Hussein Adel
Hussein Adel el 29 de Mayo de 2020
no one since 2011 :)
Steven Lord
Steven Lord el 29 de Mayo de 2020
No one responded since February 1st, 2018. The answers given then and back in 2011 are still valid.

Iniciar sesión para comentar.

 Respuesta aceptada

Greg Heath
Greg Heath el 7 de Oct. de 2011
Editada: Greg Heath el 1 de Feb. de 2018

8 votos

rand is an obsolete random number generator that generates uniformly distributed outputs in the open interval (0,1).
rand(m,n) produces a matrix of size [m n] and rand(n) = rand(n,n)
Each time rand is called, the state of the generator is changed and a new sequence of random numbers is generated.
There are 2^1492 states, 2^32 of them are so-called integer states.
rand('state',N) for integer N in the closed interval [0 2^32-1] initializes the generator to the Nth integer state.
SEE THE DOCUMENTATION:
help rand
doc rand
Hope this helps.
Greg

1 comentario

Steven Lord
Steven Lord el 1 de Feb. de 2018
Greg, I have a slight issue with the way your first sentence is worded. The rand function is not obsolete; it is the recommended way to generate uniform random numbers.
The particular syntax for rand about which the poster asked, where you use it to control the internal state information about the pseudorandom number generators, is what is discouraged (though describing it as obsolete is close enough.) We recommend using the rng function instead.

Iniciar sesión para comentar.

Más respuestas (4)

Wayne King
Wayne King el 7 de Oct. de 2011

1 voto

did you read that document, it is explained there. It is a seed. The seed is an integer, you can use it to produce repeatable results.
rand('state',11)
rand(4,1)
% now seed back to where you were
rand('state',11)
rand(4,1)
% the same 4 numbers both times, now
rand('state',1)
rand(4,1)
% see they're different
Wayne King
Wayne King el 7 de Oct. de 2011
Editada: John Kelly el 27 de Mayo de 2014

0 votos

rand('state',seed_number) is an old way of seeding the MATLAB v5 random number generator.

1 comentario

habady
habady el 7 de Oct. de 2011
in either cases i need to understand, what does it mean or refer to

Iniciar sesión para comentar.

Steven Lord
Steven Lord el 1 de Feb. de 2018

0 votos

See this page in the documentation for an explanation of that syntax and the recommended replacement.
yasmine Zem
yasmine Zem el 26 de En. de 2021

0 votos

Bonjour j'ai un problème avec mon algorithme il veut pas marcher je voudrais avoir des explications svp clf
randn ('state',1)
T = 1; N = 2^8; Delta = T/N; lambda = 0.05; sigma 0.8; Xzero = 1;
Xem = zeros (1, N+1);
Xem (1) = Xzero;
for j = 1:N
Winc = sqrt (Delta) *randn;
Xem (j+1)=abs (Xem (j) + Delta*lambda*Xem (j) + sigma\sqrt(Xem (j)) *Winc);
end
plot ( [0:Delta:T],Xem, 'r--') xlabel ('t','FontSize', 16), ylabel ('X', 'FontSize', 16)

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Oct. de 2011

Respondida:

el 26 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by