Random seed in Simulink - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Random seed in Simulink

tako_belltako_bell Posts: 11Member
im new to Simulink so please be easy on me with u'r answers.
I need to generate a number with in the [1,5] values and i need the number to be different every simulation, is there any comand to generate a random seed and not get the same seed every simulation.
I know i can change the seed manual in the random blook, but this is not a good solution for my problem, i need the random to be "Monte Carlo" style.

Thank you.


  • giuggiug Posts: 217Member
    There is a simulink block named [u]random number[/u]. It is in the simulink [u]sources[/u] library.
  • tako_belltako_bell Posts: 11Member
    Sorry but your idea didnt work,
    I made a simple simulation that has only a random number block and a scope , I ran the simulation 3 times, each time the scope had shown the same 3 numbers.
    What i need is that in every simulation i'll get different numbers.

    Thank you.
  • giuggiug Posts: 217Member
    Ok, you can use the [u]matlab function[/u] block and then the function [u]rand[/u] or [u]randn[/u]. It gives different results for different simulations.
  • tako_belltako_bell Posts: 11Member
    im sorry but like ur last solution this one didnt work as well.
    I made a simple simulation that has an embedded matlab function blook
    and a scope, the matlab funtion i wrote was :
    function y = fcn()
    % This block supports the Embedded MATLAB subset.
    % See the help menu for details.

    y = rand(1);
    //end of function

    The scope had shown me the same result in each simulation i ran.

    Thank you.
  • giuggiug Posts: 217Member
    Not the embedded matlab function, even if I think that it has to work well, but [u]MATLAB function[/u], and in the properties of the block you have to specify "rand" or "randn".
    I try this

    constant (1) --> Matlab function (rand) --> scope.

    It gives me always different values
  • tako_belltako_bell Posts: 11Member
    Thank you, this solution is what i was looking for.

  • giuggiug Posts: 217Member
    I'm glad I could help!
Sign In or Register to comment.