# Shuffle

```cpp
/**
 * Shuffle an array of numbers.
 */

/*
The Algorithm:
- Nothing much to say, expect that
  swapping each index with another
  random index ensures that every
  index had an equal opportunity to 
  enter any other index.
*/

void shuffle(vector<int> &elements)
{
    srand(time(nullptr));
    for (int i = 0; i < elements.size(); i++)
    {
        int swap_i = rand() % elements.size();
        swap(elements.at(0), elements.at(swap_i));
    }
}

int main()
{
    vector<int> ar = { 1,2,3,4,5,6 };
    shuffle(ar);
    print(ar);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/probability/shuffle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
