Question: As the title of this post, I found the answer regarding "Can we put subviews of a UIView in front of its CALayer" in [this](https://stackoverflow.com/questions/6551394/put-subviews-of-a-uiview-in-front-of-its-calayer) post, but I cannot find the answer to *why* this is so. In my opinion, having the view as the subview of the layer's view only suggests "stronger" order between the subview and the layer. Can somebody explain this to me?

Answer: 
You can use `combinations` to generate all pairs and use `sample` to choose randomly. Admittedly only lazy in the "not much to type" sense, and not in the use a generator not a list sense :-)

```
from itertools import combinations
from random import sample

n = 100
sample(list(combinations(range(1,n),2)),5)

```

If you want to improve performance you can make it lazy by studying this 
[Python random sample with a generator / iterable / iterator](https://stackoverflow.com/questions/12581437/python-random-sample-with-a-generator-iterable-iterator)

the generator you want to sample from is this: `combinations(range(1,n)`
I don't think any thing on your line can improve. After all, as your `m` get closer and closer to the limit `n(n-1)/2`, you have thinner and thinner chance to find the unseen pair.

I would suggest to split into two cases: if `m` is small, use your random approach. But if `m` is large enough, try

```
 pairs = list(itertools.combination(buffet,2))
 ponits = random.sample(pairs, m)

```

Now you have to determine the threshold of `m` that determines which code path it should go. You need some math here to find the right trade off.