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

Latest commit

 

History

History
23 lines (17 loc) · 734 Bytes

shuffle.md

File metadata and controls

23 lines (17 loc) · 734 Bytes

shuffle

Description :This function can rearranges the elements in the range randomly

Example:

    // Creating array of size 5
    std::array<int,5> random {1,2,3,4,5}; // 1,2,3,4,5

    // Obtain a time-based seed:
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

    // Rearranges the elements in the range [first,last) randomly
    shuffle (random.begin(), random.end(), std::default_random_engine(seed));

    std::cout << "Shuffle:";

    // Print the content in array random
    for (int& x: random) std::cout << ' ' << x;
    std::cout << '\n';

See Sample code Run Code