I've encountered this problem when using functions in combination with user input and rng(s). To clarify my problem, I've got the following 2 scripts:
%main.m
user_seed = "1739995225";disp(['Main input seed = ' char(user_seed)]);checkSeed(user_seed)
and
%checkSeed.m
function checkSeed(user_seed) %clear s seeder;
seeder = double(user_seed); %check if seed isset
if exist('seeder','var') == 1 s = rng(seeder); disp(['Function seed = ' num2str(s.Seed)]); else s = rng('shuffle'); disp(['random seed = ' num2str(s.Seed)]); endend
The issue is that everytime the previous user seed is being used instead of the current one. For example
%first run
user_seed = "1739995225";%Main input seed = 1739995225
%Function seed = 1739995225
%second run
user_seed = "1739995226";%Main input seed = 1739995226
%Function seed = 1739995225%third run
user_seed = "1739995227";%Main input seed = 1739995227
%Function seed = 1739995226
I tried putting the checkSeed.m contents in the main script, but that gave me the same result. Also tried adding clear s seeder; to the function but that didnt help either. So any ideas?
Best Answer