## Matlab

Moderators: None (Apply to moderate this forum)
Number of posts: 2147

This Forum Only

Random seed in Simulink Posted by tako_bell on 7 Apr 2009 at 12:55 AM
Hi,
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.
Re: Random seed in Simulink Posted by giug on 7 Apr 2009 at 1:11 AM
There is a simulink block named random number. It is in the simulink sources library.
Re: Random seed in Simulink Posted by tako_bell on 7 Apr 2009 at 1:41 AM
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.
Re: Random seed in Simulink Posted by giug on 7 Apr 2009 at 2:10 AM
Ok, you can use the matlab function block and then the function rand or randn. It gives different results for different simulations.
Re: Random seed in Simulink Posted by tako_bell on 7 Apr 2009 at 2:27 AM
Hi,
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.
Re: Random seed in Simulink Posted by giug on 7 Apr 2009 at 2:36 AM
Not the embedded matlab function, even if I think that it has to work well, but MATLAB function, 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
Re: Random seed in Simulink Posted by tako_bell on 7 Apr 2009 at 2:51 AM
Thank you, this solution is what i was looking for.
:)

Re: Random seed in Simulink Posted by giug on 7 Apr 2009 at 3:06 AM

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic