title: Matlab: Get list of ordered pairs
body: <p>Let me explain with an example: If I give '4' as input, I want the pairs (1,2), (1,3), (1,4),(2,3),(2,4),(3,4) in a matrix like so:</p>
  
  <pre><code>1 2
  1 3
  1 4
  2 3
  2 4
  3 4
  </code></pre>
  
  <p>Why do I need this? I will generate a random number from 1 to (n*(n-1)/2) and I want the corresponding pair. I figured I will generate the pair list first and then use the random number as an index. If there is a direct solution to this, then much better!</p>
  
  <p>Edit: 
  Actually I don't need all pairs, I need t random ordered pairs that don't repeat and first value &lt; second value. There are 5000 lists each with n elements. So total pairs possible is tot = 5000 * n * (n-1)/2. If I generate t random integers from 1 to tot using randperm, can I translate it into a pair? I can get the list number by dividing by 5000. And if I mod with 5000, I will get pair index. I was trying to convert this pair index into a pair. Sorry for not explaining all this before. Hope I am clear.</p>