You're on the right track. Choose a random seed when the GUI initializes and store it in your GUI using guidata() so all components have access to it and can reseed it whenever necessary. Here's a demo. Based on your examples, I'm assuming you're not using app designer.
function myOpeningFcn(hObject, . . .)
. . .
handles.rngSeed = randi(2^32 - 1);
guidata(hObject, handles);
end
function myCallbackFcn(. . ., handles)
. . .
rng(handles.rngSeed)
end
Another good idea would be to add the following line to your closereq function so that your rng seed is randomized again.
Best Answer