Last Updated : 10 Apr, 2024
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() 
{
    vector <int> vec;
    for(int i = 1; i < 10; i++)
        vec.push_back(i);
     
    random_shuffle(vec.begin(), vec.end());
    for(int i = 0; i < 10; i++)
     cout << vec[i] << \" \";
    
    return 0;
} 

Predict the output of the above program.
(A) 1 2 3 4 5 6 7 8 9 0
(B) 0 1 2 3 4 5 6 7 8 9
(C) 5 4 8 9 1 6 3 2 7 0
(D) None of the mentioned


Answer: (C)

Explanation:
random_shuffle(): It randomly rearrange elements in range [first, last). The function swaps the value of each element with some other randomly picked element.


Share your thoughts in the comments