@jutge.org/toolkit 4.2.24 → 4.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,9 @@ public:
22
22
  */
23
23
  vector<int> random_permutation (int n);
24
24
 
25
+ template<class C>
26
+ vector<C> shuffle_vector(const vector<C>& v);
27
+
25
28
 
26
29
  //////// STUDENTS DO NOT NEED TO READ BELOW THIS LINE ////////
27
30
 
@@ -85,4 +88,13 @@ inline vector<int> Random_generator::random_permutation (int n) {
85
88
  return v;
86
89
  }
87
90
 
91
+ template<class C>
92
+ inline vector<C> Random_generator::shuffle_vector (const vector<C>& v) {
93
+ // Random shuffle
94
+ vector<int> aux = random_permutation(v.size());
95
+ vector<C> res_shuff(v.size());
96
+ for (uint i = 0; i < aux.size(); ++i) res_shuff[aux[i]] = v[i];
97
+
98
+ return res_shuff;
99
+ }
88
100
  #endif