title: Generate random non-repeating integers from a small range
body: <p>What I'm trying to accomplish is the following:</p>
  
  <p>I wish to create a vector of integers, from a relatively small range, and ensure that none of the integers will be followed by the same integer.</p>
  
  <p>i.e., This is a "legal" vector:
  [ 1 3 4 2 5 3 2 3 5 4 ]</p>
  
  <p>and this is an "illegal" vector (since 5 follows 5):
  [ 1 3 4 2 5 5 2 3 5 4 ]</p>
  
  <p>I've experimented with <code>randi</code>, and all sorts of variations with <code>randperm</code>, and I always get stuck when i try to generate a vector of around 100 elements, from a small range (i.e., integers between 1 and 5).</p>
  
  <p>The function just runs for too long.</p>
  
  <p>Here's one of the attempts that i've made:</p>
  
  <pre><code>function result = nonRepeatingRand(top, count)
  
      result = randi(top, 1, count);
  
      while any(diff(result) == 0)
           result = randi(top, 1, count);    
      end
  
  end
  </code></pre>
  
  <p>Any and all help will be much appreciated. Thanks !</p>