title: Pseudo random number generator
body: <p>I'm trying to implement a pseudo random number generator in MATLAB. I'm building it according to the following recipe:</p>
  
  <ol>
  <li><p>Create the random number generator seed, x_0. Get and save bits 8...15 of x_0 to the cell named random_numbers.</p></li>
  <li><p>For Loop: Create the next n numbers using rem( (25173 * previous_number + 13849) + 2^16) ). Save bits 8...15 of number n to the cell named random_numbers. Print number n.</p></li>
  </ol>
  
  <p>Step 1:</p>
  
  <pre><code>n = 2000;
  
  % Pre-allocate cell with size n numbers
  random_numbers = cell(1, n);
  
  % Generate seed in range 1 - 2^16 - 1
  x_0 = randi([1, 2^16-1]);
  
  % Save seed as binary array of size 16 bits
  x_0 = de2bi(x_0, 16);
  
  % Extract bits 8...15 from seed
  x_0 = x_0(8:15);
  
  % Add bits 8...15 from seed to cell
  random_numbers{1} = x_0;
  </code></pre>
  
  <p>Step 2:</p>
  
  <pre><code>for x = 2:n
      % Get previous number as base 10 number
      previous_number = bi2de(random_numbers{x - 1});
  
      % Calculate random number
      random_number = rem( (25173 * previous_number + 13849), 2^16 );
  
      % Convert random number to binary, extract bits 8...15
      random_number = de2bi(random_number, 16);
      random_number = random_number(8:15);
  
      % Save bits 8...15 of random number to cell
      random_numbers{x} = random_number;
  
      % Print bits 8...15 of random number as decimal number
      disp(num2str(bi2de(random_number)))
  end
  </code></pre>
  
  <p>So what's the problem? If you run this code you'll notice that the initial numbers are unique. The initial numbers do not repeat themselves. However the remaining numbers created with this algorithm do follow a certain pattern. I want every number to follow the same pattern. It would be very much appreciated if someone could help me figure out what I'm doing wrong.</p>