Question: I want to compute `K*es` where `K` is an `Eigen` matrix (dimension `pxp`) and `es` is a `px1` random binary vector with 1s. 

For example if `p=5` and `t=2` a possible `es` is `[1,0,1,0,0]'` or `[0,0,1,1,0]'` and so on...

How do I easily generate `es` with `Eigen`?

Answer: 
I came up with even a better solution, which is a combination of `std::vector`, `Egien::Map` and `std::shuffle`.

```
std::vector<int> esv(p,0);
std::fill_n(esv.begin(),t,1);
Eigen::Map<Eigen::VectorXi> es (esv.data(), esv.size());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(std::begin(esv), std::end(esv), g);

```

This solution is memory efficient (since `Eigen::Map` doesn't copy `esv`) and has the big advantage that if we want to permute `es` several times (like in this case), then we just need to repeat `std::shuffle(std::begin(esv), std::end(esv), g);`

Maybe I'm wrong, but this solution seems more elegant and efficient than the previous ones.
When `t` is close to `p`, Ryan's method need to generate much more than `t` random numbers. To avoid this performance degrade, you could solve your original problem

> 
> find `t` different numbers from [0, p) that are uniformly distributed
> 
> 
> 

by the following steps

1. generate `t` uniformly distributed random numbers `idx[t]` from [0, p-t+1)
2. sort these numbers `idx[t]`
3. `idx[i]+i, i=0,...,t-1` are the result

The code:

```
VectorXi idx(t);
VectorXd es(p);
es.setConstant(0);

for(int i = 0; i < t; ++i) {
  idx(i) = int(double(rand()) / RAND_MAX * (p-t+1));
}

std::sort(idx.data(), idx.data() + idx.size());

for(int i = 0; i < t; ++i) {
  es(idx(i)+i) = 1.0;
}

```