Two Matlab Function Blocks generate the same random number

4 Ansichten (letzte 30 Tage)
Benjamin Krüger
Benjamin Krüger am 7 Jan. 2018
Beantwortet: Manan Mishra am 10 Jan. 2018
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!

Antworten (1)

Manan Mishra
Manan Mishra am 10 Jan. 2018
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)

Community Treasure Hunt

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

Start Hunting!

Translated by