【发布时间】:2015-08-09 13:36:47
【问题描述】:
考虑vector<vector<int> > Vec。
我想洗牌 Vec 内每个 vector<int> 中的 int 值,并对 vector< vector<int> > 执行洗牌。
如何在 C++ 中做到这一点?
我的主要目标是随机化一个整数矩阵,我使用vector<vector<int> > Vec 实现了它。
目前,我正在尝试这样做:
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
for(int i=0;i<Vec.size();i++) {
shuffle(Vec[i].begin(), Vec[i].end(), std::default_random_engine(seed));
}
shuffle(Vec.begin(),Vec.end());
// gives an error:
cluster.cpp:36:27: error: no matching function for call to ‘shuffle(std::vector<std::vector<int> >::iterator, std::vector<std::vector<int> >::iterator)’
【问题讨论】:
-
什么错误?我们应该猜吗?
-
您使用
#include <algorithm>并使用std::shuffle()(限定名)吗? -
是的,我确实包含了它们。
-
您似乎对每个 行 使用相同的种子。此外,您在最后一次致电
std::shuffle时没有提供随机引擎