Why does my compiled RAND function give the same values every time I run my MATLAB-generated standalone application?
Show older comments
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.
Accepted Answer
More Answers (1)
Greg
on 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.
Categories
Find more on Application Deployment in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!