## Google Interview Question

Software Engineers**Country:**United States

```
vector<int> GetRandomSublist(vector<int> A, int n)
{
default_random_engine seed((random_device())());
if (n < 0 || n >= A.size()) return {};
for (int i = 0; i < n; i++)
{
uniform_int_distribution<int> rand_gen(i, A.size() - 1);
int num = rand_gen(seed);
swap(A[i], A[num]);
}
vector<int> ret;
for (int i = 0; i < n; i++)
ret.emplace_back(A[i]);
sort(ret.begin(), ret.end());
return ret;
}
```

- jeff July 04, 2019