Code covered by the BSD License  

Highlights from
Control random numbers in Simulink

image thumbnail

Control random numbers in Simulink


John (view profile)


Control random numbers in Simulink matlab function and random number generator

%This script sets up the seed model. Its purpose is to demonstrate a way to
%save the random seed so that all simulations can be replicated. -- jrw
close all; clear all; clear mex

%set a random seed for the embedded matlab functions
%s = RandStream.create('mt19937ar','seed',sum(100*clock));
%s = RandStream.create('mt19937ar','seed',1);
%defaultStream = RandStream.getDefaultStream;
%savedState = defaultStream.State;
%u1 = rand(1,5)
%defaultStream.State = savedState;
%u2 = rand(1,5)

runs = 5;
sim_time = 10;
update_rate = 1;
run_seed = 1:runs;
run_output = zeros(runs,round(sim_time/update_rate)+1);
run_output2 = run_output;
run_output3 = run_output;
for i = 1: runs
    r_seed = run_seed(i);
    s = RandStream.create('mt19937ar','seed',r_seed);
    %defaultStream.State = savedState;
    run_output(i,:) = source_output;
    run_output2(i,:) = embed_output;
    run_output3(i,:) = gam_embed_output;


Contact us