Two Matlab Function Blocks generate the same random number

3 次查看(过去 30 天)
In Simulink, I'm using a Matlab function block to generate Gaussian-distributed numbers at each time step. If I make a copy of that block and run it in parralel to the first one, it generates the same random number (instead of an independent one as actually wanted). A quick-and-dirty solution for this problem is to generate a random vector (in this example with a length of two) and let each block pick one element, but I'm wondering if there is a more elegant way to do it?
Thanks for your help!

回答(1 个)

Manan Mishra
Manan Mishra 2018-1-10
You can use different seeds in your MATLAB function blocks to get different random numbers as output. Look at the following documentation for more information regarding this:
You can include something like this in your MATLAB functions before calling the random number generator function:
In block 1:
>> rng(1)
In block 2:
>> rng(2)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by