code: def random_pairs_without_replacement_large_frames(
          n, shape, random_state=None):
      
  
      n_max = max_pairs(shape)
  
      sample = np.array([])
  
      # Run as long as the number of pairs is less than the requested number
      # of pairs n.
      while len(sample) < n:
  
          # The number of pairs to sample (sample twice as much record pairs
          # because the duplicates are dropped).
          n_sample_size = (n - len(sample)) * 2
          sample = random_state.randint(n_max, size=n_sample_size)
  
          # concatenate pairs and deduplicate
          pairs_non_unique = np.append(sample, sample)
          sample = _unique_rows_numpy(pairs_non_unique)
  
      # return 2d indices
      if len(shape) == 1:
          return _map_tril_1d_on_2d(sample[0:n], shape[0])
      else:
          return np.unravel_index(sample[0:n], shape)
docs: Make a sample of random pairs with replacement