Generating random number

%random number generation
clear; clc;

%generate an random number between 0 and 1
a = rand;

% generte 2*2 matrix of uniformly distributed (0,1) random numbers
b = rand(2);

% generate 3*2 matrix of uniformly distributed (0,1) random numbers
c = rand(3,2);

% generate random nos of std normal distribution
% to generate random numbers in normal distribution with mean = 0 and
% variance = 1
d = randn;

% generate 2*2 matrix of random numbers in normal distribution
e = randn(2);

%generate 3*2 matrix of random numbers in normal distribution
f = randn(3,2);
%generate uniformly distributed random numbers between a=7 and b =12
clear;clc;

a = 7;
b = 12;
c = rand;
d = rand(3,2)

%generate an random number
uniform_rn = a+(b-a)*c;

%generate a martix of random number between 3 by 2
uniform_rn_matrix = a+(b-a)*d;

Setting a seed

%setting a seed
%generate uniformly distributed random numbers between a=7 and b =12
clear;clc;

% keeps the generation of random number constant
RandStream.setGlobalStream(RandStream('mt19937ar','seed',1729));

a = 7;
b = 12;
c = rand;
d = rand(3,2)

%generate an random number
uniform_rn = a+(b-a)*c;

%generate a matrix of random number between 3 by 2
uniform_rn_matrix = a+(b-a)*d;

results matching ""

    No results matching ""