title: Random number generator in Matlab
body: <p>I am generating random sequences of numbers using the same seed:</p>
  
  <pre><code>sprev = rng(2,'v5uniform');
  for i=1:N
      %do some operations      
      rndIDX = randperm(sampleSize) ; 
      newdata= data(rndIDX(1:newSampleSize), :) ;
      if x&gt;y
         remove=x1; %line 7
      end
      for l=1:M
          %do something else
          if l&gt;xy &amp; ~empty(remove)
             %do something related to remove
          elseif l&gt;xy
             %do nothing
          else
             %do something not related to remove
          end
          %more code here
      end
   end
  </code></pre>
  
  <p>However, when I comment out line 7, rndIDX returns a different sequence of numbers which for me is unexpected. There might be a bug somewhere in the code but I am not sure what is the relationship between the sequence produced by <code>randperm</code> and the code that follows. Also, if i keep the code as presented I always get the same newdata which is the expected behaviour. I just want to comment out line 7 and still get the same newdata.I can confirm that <code>sampleSize</code> is always the same as well as <code>newSampleSize</code> for both cases.</p>