function out =mlhdlc_rand
 
%The algorithm has been taken from : https://ieeexplore.ieee.org/document/8053004  

persistent state ;
mask_1 = uint32(hex2dec('80000000'));
mask_2 = uint32(hex2dec('7FFFFFFF'));
a = uint32(hex2dec('9908B0DF'));
seedValue = 398; %seed value
const1 = -11;
const2 = 7;
const3 = -15;
const4 = 18;

% loading the .mat file
if isempty(state)
     
    state1 = coder.load('rand_input.mat', 'rand_input');
    state = uint32(state1.rand_input);
        
end
 
p = bitand((state(1)), mask_1);
q = bitand(state(2), mask_2);
r = bitor(p, q);
shift = bitxor(bitshift(r,1),state(seedValue)); 
if bitget(r,1) == 0
    s = shift;
else
    s = bitxor(shift,a);
end
 
 % According to the algorithm the below bit operation have to be performed
 s = bitxor(s, bitshift(s, const1));
 s = bitxor(s, bitand(bitshift(s, const2) , uint32(hex2dec('9D2C5680'))));
 s = bitxor(s, bitand(bitshift(s, const3) , uint32(hex2dec('EFC60000'))));
 out = (bitxor(s, bitshift(s, const4)));
 
 state = uint32(vertcat(state(2:end),s));
  
end