
I'm using Simevents and can't change the random seed in the Event Generator.
조회 수: 4 (최근 30일)
이전 댓글 표시
I've added a iterSeed generator in the InitFcn* callback...
disp('Changed random seed to')
iterSeed = randi(400)
And in the Event Generator I want to test how dt = randi([1 3]) varies with different seeds to change to see how a different random string plays out....
I've tried all the suggested approachs below, but none seem to work.
persistent rngInit;
%if isempty(rngInit)
% disp('Changed seed inside Entity Gen to:')
% iterSeed
% rngInit = true;
%end
persistent rngInit;
if isempty(rngInit)
fid = fopen('/dev/random');
rndval = fread(fid,1,'uint32')
fclose(fid);
seed = rndval(1);
rng(seed);1
rngInit = true
end
dt = randi([1 3])
%persistent rngInit;
%if isempty(rngInit)
% rng(iterSeed);
% disp('Changed seed inside Entity Gen to:')
% iterSeed
% rngInit = true;
%end
%persistent rngInit;
%if isempty(rngInit)
% seed = 12345;
% rng(seed);
% rngInit = true;
%end
댓글 수: 0
답변 (1개)
Altaïr
2025년 4월 15일
편집: Altaïr
2025년 4월 15일
A variable in the base workspace can be used to store the seed value and then applied within the Entity Generator. Here's how this can be done:
First, create a variable named 'seedVal' in the base workspace, and set it to the seconds value of the current system time with the following line:
seedVal=second(datetime())
Then, use these lines in the Intergeneration time action code field of the Entity Generator:
persistent rngInit;
if isempty(rngInit)
rng(seedVal);
rngInit = true;
end
dt = randi([1 3]);
This setup allows the intergeneration time to vary with simulation time as well as with the seed value.

For more detailed information on specifying intergeneration times, refer to this link: https://www.mathworks.com/help/releases/R2024a/simevents/ug/specifying-intergeneration-times-for-entities.html
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete-Event Simulation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!