No true random for standalone (files only) in AppDesigner?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
i wrote an App with the AppDesigner which includes Monte Carlo Simulatoin with multiple random generators.
When I execute the app multiple time directly within the app designer everything is as is should be. The distributions are similiar but every single index of the array has a different (random) value.
For distribution I decided that colleagues shall download the runtime and they get a standalone .exe file. But here I happens that when you execute the app 2 times with the very same inputs you get for every index of the array the same value.
Question 1: Is that a bug?
Question 2: Is there an easy workaround, in which I can keep the standalone .exe distribution.
I already tried to tic toc some times in functions to get a random-like input and wrote dem to a struct (app.a.b=toc), but the random still led to always the same result.
Thanks
0 comentarios
Respuestas (2)
the cyclist
el 11 de Mayo de 2023
Disclaimer: I've never used AppDesigner, or distributed standalone MATLAB exe files.
Sounds like it is starting from the default initial seed each time. Can you put
rng shuffle
in the code, to ensure a different random number seed?
2 comentarios
the cyclist
el 11 de Mayo de 2023
As @Steven Lord mentions in his answer, but bears repeating because it is important, it is recommended to insert that seed-setting line into your code just once (before the first call to any function that uses the random number generator), and not before each call.
Steven Lord
el 11 de Mayo de 2023
Question 1: Is that a bug?
No. See this documentation page for an explanation. While that talks about MATLAB startup, it also applies to starting the MATLAB runtime.
Question 2: Is there an easy workaround, in which I can keep the standalone .exe distribution.
See that documentation page I linked above. But note that you shouldn't reseed the generator every time you draw a new random number as per the Note on this documentation page.
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown 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!