MATLAB: Can the value of rand(‘seed’) be saved

random number generator

I set random seed value as 0
rand('seed',0);
then i do genetic algorithm using ga
Is there any way i can save the value of rand('seed',0)
so that i can use it without calling rand('seed',0)
Just load it and call function ga

Best Answer

"Is there any way i can save the value of rand('seed',0) so that i can use it without calling rand('seed',0) Just load it and call function ga"
Yes. You can create a figure and give it a CreateFcn which executes that command. You can make it 'Visible', 'off' so it does not occupy anything on the screen.
Then save the handle of the figure as part of the .mat file .
When you load the .mat file and so load the figure that is contained inside it, the CreateFcn of the figure will be executed; you would have given it code that sets the random seed for you, so the random seed will be changed.
I do not at all recommend this approach: I would suggest that you instead provide a small function or script that loads your data and sets the random seed, and possibly which also starts ga executing.
Note: rand('seed',value) is considered obsolete. You should be using
rng(0, 'v4')
instead.