Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

 

History

History
33 lines (23 loc) · 957 Bytes

random_shuffle.md

File metadata and controls

33 lines (23 loc) · 957 Bytes

random_shuffle

Description : It randomly rearrange elements in range [first, last). The function swaps the value of each element with some other randomly picked element. When provided, the function gen determines which element is picked in every case. Otherwise, the function uses some unspecified source of randomness.

Example:

      srand(unsigned(time(0)));
      vector<int> arr;

      // set some values:
      for (int j = 1; j < 10; ++j)

      arr.push_back(j);

      // using built-in random generator
      random_shuffle(arr.begin(), arr.end());

      // using randomfunc
      random_shuffle(arr.begin(), arr.end(), randomfunc);

      // print out content:
      cout << "arr contains:";
      for (auto i = arr.begin(); i != arr.end(); ++i)
      cout << ' ' << *i;

      cout << endl;

      return 0;

See Sample code Run Code