code: def randomPairs(n_records, sample_size):
      
      n = int(n_records * (n_records - 1) / 2)
  
      if sample_size >= n:
          random_pairs = numpy.arange(n, dtype='uint')
      else:
          try:
              random_pairs = numpy.array(random.sample(range(n), sample_size),
                                         dtype='uint')
          except OverflowError:
              return randomPairsWithReplacement(n_records, sample_size)
  
      b = 1 - 2 * n_records
  
      root = (-b - 2 * numpy.sqrt(2 * (n - random_pairs) + 0.25)) / 2
  
      i = numpy.floor(root).astype('uint')
      j = numpy.rint(random_pairs + i * (b + i + 2) / 2 + 1).astype('uint')
  
      return zip(i, j)
docs: Return random combinations of indices for a square matrix of size n
      records. For a discussion of how this works see
      http://stackoverflow.com/a/14839010/98080