How to generate same set of random numbers?
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Will Smith
el 12 de Oct. de 2016
Comentada: Walter Roberson
el 13 de Jul. de 2021
How to generate same set of random numbers time and again?
0 comentarios
Respuesta aceptada
Abhishek Jain
el 12 de Oct. de 2016
You can control random number generation using 'rng()' function. The usage is rng(seed).
rng(seed) seeds the random number generator using the nonnegative integer seed so that rand, randi, and randn produce a predictable sequence of numbers.
Hope that helps..!!
Más respuestas (2)
Yaxuan Li
el 13 de Jul. de 2021
Editada: Walter Roberson
el 13 de Jul. de 2021
Why this doens't work for me?
rng(1,'twister');
x = rand(1,5)
x =
0.4170 0.7203 0.0001 0.3023 0.1468
x = rand(1,5)
x =
0.0923 0.1863 0.3456 0.3968 0.5388
1 comentario
Walter Roberson
el 13 de Jul. de 2021
You need to reset the seed.
rng(1,'twister');
x = rand(1,5)
rng(1,'twister');
x = rand(1,5)
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!