(C++) StdRandom\_shuffleExample1
February 24, 2017 · View on GitHub
(C++) StdRandom_shuffleExample1
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
Qt project file: ./CppStdRandom_shuffleExample1/CppStdRandom_shuffleExample1.pro
QT += core QT -= gui CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
./CppStdRandom_shuffleExample1/main.cpp
#include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> v; for (int i=0; i!=5; ++i) v.push_back(i); std::cout << "Before shuffling:\n"; for(int i=0;i!=5; ++i) std::cout << v[i] << '\n'; std::random_shuffle(v.begin(),v.end()); std::cout << "After shuffling:\n"; for(int i=0;i!=5; ++i) std::cout << v[i] << '\n'; }