Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Shuffle algorithm
//Title of this code #include <iostream> #include <cstdlib> #include <ctime> #include <vector> using namespace std; /* v1 = rand() % 100; // v1 in the range 0 to 99 v2 = rand() % 100 + 1; // v2 in the range 1 to 100 v3 = rand() % 30 + 1985; // v3 in the range 1985-2014 */ void shuffle(vector<int>& t) { for (int i = t.size() - 1; i > 0; --i) { int p = rand() % i; swap(t[i], t[p]); } } void printVector(vector<int>& t) { for (int i= 0; i < t.size(); ++i) cout << t[i] << " "; cout << endl; } int main() { vector<int> t; t.push_back(1); t.push_back(2); t.push_back(3); t.push_back(4); t.push_back(5); t.push_back(6); srand (time(NULL)); for (int i = 0; i < 40; ++i) { printVector(t); shuffle(t); } }
run
|
edit
|
history
|
help
0
Test 8(2020)
32bit
5345
Dar
combine c++ string with dynamically allocated c array of chars through overloaded add operator
Count squares
Test 7(2020)
Graph Theory
std::erf versus erf_impl (Abramowitz & Stegun)
StackQuiz