Why does my compiled RAND function give the same values every time I run my MATLAB-generated standalone application?
Mostrar comentarios más antiguos
I tried to compile the code below to an executable:
function myrand
a=rand(4,1);
disp(a)
When I run the executable, the RAND function always returns the same set of numbers. However, if I run the code in MATLAB, the function gives different results when I call it repeatedly.
The same thing happens if I generate the executable with the Matlab Coder.
Respuesta aceptada
Más respuestas (1)
Greg
el 24 de Oct. de 2018
In R2013a, "getDefaultStream" was replaced by "getGlobalStream" for the RandStream. Prior to that, it generated warnings indicating its eventual removal, but it began erroring in R2013a. For releases R2013a - R2018b (possibly later, but R2018b is the latest at time of writing), use:
reset(RandStream.getGlobalStream,sum(100*clock));
For releases prior to R2013a, see the other answer.
Categorías
Más información sobre Application Deployment en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!