Why does my compiled RAND function give the same values every time I run my MATLAB-generated standalone application?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Greg
le 24 Oct 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.
Catégories
En savoir plus sur Application Deployment dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!