Is there a way to generate unique random number in Simevents?
5 次查看(过去 30 天)
显示 更早的评论
I am currently working with Queueing Network model using Simevents. Each server has service time, and I am using rand and randn to generate random service time for each server (for ex, -1 * 0.22 * log(1 - rand()) + 0.13 or 0.3+0.1*randn). I realized that most of the entity's service time are the same. I have tried generating seed, but it's still the same service time. I have followed
these two documents, but the result are the same (I also used rng('shuffle'), but still doesn't work)
Is there a way to generate unique random number using rand() and randn() other than the methods I used in simevents? Thank you.
0 个评论
回答(1 个)
Brahmadev
2023-9-14
Hi,
I understand that you would like to generate random numbers using Entity Generator. The following code as the "Intergeneration time action" should give different results on each simulation.
% coder.extrinsic is used to make sure that all interactions with the
% random number generator (RNG) and rand() are executed outside of Simulink
coder.extrinsic("rng");
rng('shuffle');
coder.extrinsic("rand");
% You need to explicitly mention the type for the variable that is receiving values
% from a function declared as coder.extrinsic. If not, MATLAB will return value of type mxArray.
newValue = double(0);
newValue = rand();
disp(newValue);
dt = -1*0.22*log(1-rand()) + 0.13 ; % Values generated at random service time
Hope this helps!
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!