#include <iostream> #include <vector> #include <algorithm> #include <random> typedef std::vector<std::size_t> Vec; Vec MakeData(std::size_t N){ Vec V(N); std::size_t i = 0; for (auto& o : V) o = i++; return V; } bool BlockMove(Vec& vec, std::size_t P, std::size_t Len){ P = std::min(P, vec.size()); Len = std::min(Len, vec.size()-P); Vec T; for (size_t i = P; i < P+Len; i++) T.push_back(vec[i]); for (size_t i = 0; i < P; i++) T.push_back(vec[i]); for (size_t i = P+Len; i < vec.size(); i++) T.push_back(vec[i]); vec = T; return true; } bool HandShuffle(Vec& vec){ std::random_device rd; std::mt19937 mt(rd()); //std::mt19937 mt(0); std::uniform_int_distribution<int> uid(2, 8); int P = 0; int Len = vec.size(); while (Len > 0){ P += uid(mt); Len -= uid(mt); Len = std::max(Len, 0); P = std::min<int>(P, vec.size() - Len); BlockMove(vec, P, Len); } return true; } bool MakeHoge(Vec& vec,std::size_t N){ for (size_t i = 0; i < N; i++) { HandShuffle(vec); } return true; } bool Show(Vec vec){ std::cout << "Result:"; for (auto& o : vec) std::cout << o << ','; std::cout << std::endl; return true; } int main(){ Vec vec = MakeData(53); MakeHoge(vec, 5); Show(vec); std::cout << std::endl; std::sort(vec.begin(), vec.end());//デバッグ用 Show(vec); return 0; }
Standard input is empty
Result:17,18,51,49,13,14,19,21,22,26,20,24,28,7,29,30,3,42,50,52,31,32,33,34,35,36,37,38,39,25,40,41,0,10,12,45,46,47,11,48,15,23,27,43,44,1,2,4,5,6,8,9,16, Result:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,