Skip to content

Instantly share code, notes, and snippets.

@nodakai
Created February 17, 2016 11:43
Show Gist options
  • Select an option

  • Save nodakai/0fbaef4d1e82089ce03f to your computer and use it in GitHub Desktop.

Select an option

Save nodakai/0fbaef4d1e82089ce03f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <vector>
using namespace std;
void pushAll(std::vector<char> &sec, char begin, char end) {
for (char x = begin; x <= end; ++x)
sec.push_back(x);
}
int main() {
std::vector<char> chars;
pushAll(chars, 'a', 'z');
pushAll(chars, 'A', 'Z');
pushAll(chars, '0', '9');
for (char c : chars) {
cout << c ;
}
cout << endl;
for (size_t i = 0; i < chars.size(); ++i) {
const size_t rand = 12345678 * i + 23456789;
const size_t j = i + rand % (chars.size() - i);
if (i != j) // just to be careful
std::swap(chars[i], chars[j]);
}
for (char c : chars) {
cout << c ;
}
cout << endl;
for (size_t i0 = 0; i0 < chars.size(); ++i0) {
const size_t i = chars.size() - i0 - 1;
const size_t rand = 12345678 * i + 23456789;
const size_t j = i + rand % (chars.size() - i);
if (i != j) // just to be careful
std::swap(chars[i], chars[j]);
}
for (char c : chars) {
cout << c ;
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment