% This function is used for random number generation
X = [1 2 3 4 5];
%Number to use
P = [0.1 0.3 0.3 0.1 0.2 ]; % possibility to use
M = 10000; %how many numbers we want to generate
Temp = rand(1,M);
%Assign the possibility with length of intervals
% X1 - [0,0.1)
% X2 - [0.1,0.4)
% X3 - [0.4,0.7)
% X4 - [0.7,0.8)
% X5 - [0.8,1]
Index1 = find(Temp>=0
& Temp <0.1);
Index2 = find(Temp>=0.1 & Temp <0.4);
Index3 = find(Temp>=0.4 & Temp <0.7);
Index4 = find(Temp>=0.7 & Temp <0.8);
Index5 = find(Temp>=0.8 & Temp <=1);
Temp(Index1) = X(1);
Temp(Index2) = X(2);
Temp(Index3) = X(3);
Temp(Index4) = X(4);
Temp(Index5) = X(5);
Result = Temp