C++ C++;二维整数数组随机洗牌

C++ C++;二维整数数组随机洗牌,c++,arrays,multidimensional-array,vector,random,C++,Arrays,Multidimensional Array,Vector,Random,我正在尝试制作一个模拟多米诺骨牌游戏的程序。为此,我必须随机洗牌多米诺骨牌堆,但我不知道如何。我已经搜索过了,但我尝试过的一切都失败了。有办法做到这一点吗?这是我尝试的,但问题是它说种子和时间不在此范围内声明: #include <iostream> #include <vector> #include <ctime> #include <algorithm> #include <cstdlib> using namespace s

我正在尝试制作一个模拟多米诺骨牌游戏的程序。为此,我必须随机洗牌多米诺骨牌堆,但我不知道如何。我已经搜索过了,但我尝试过的一切都失败了。有办法做到这一点吗?这是我尝试的,但问题是它说种子和时间不在此范围内声明:

#include <iostream>
#include <vector>
#include <ctime>
#include <algorithm>
#include <cstdlib>


using namespace std;

class CRandom {
   public:
      vector<int>* shufflePile(){
      
         vector<int>* pile = new vector<int>;
         
         for(int i=0; i<=27; i++){
            pile->push_back(i);
         }
         srand( _Seed; unsigned (time( _Time 0)));
         random_shuffle(pile->begin(), pile->end());
         
   }

};

class CDominoes {
   int pieces [28][3] =
      {
         {0,0,1}, //1
         {1,1,1}, {1,0,1}, //2,3
         {2,2,1}, {2,1,1}, {2,0,1}, //4, 5, 6
         {3,3,1}, {3,2,1}, {3,1,1}, {3,0,1}, //7, 8, 9, 10
         {4,4,1}, {4,3,1}, {4,2,1}, {4,1,1}, {4,0,1}, //11, 12, 13, 14, 15
         {5,5,1}, {5,4,1}, {5,3,1}, {5,2,1}, {5,1,1}, {5,0,1}, //16, 17,18, 19, 20, 21
         {6,6,1}, {6,5,1}, {6,4,1}, {6,3,1}, {6,2,1}, {6,1,1}, {6,0,1} //22, 23, 24, 25, 26, 27, 28 
      };
};

class CPlayer {
};

class CTable {
};

int main() {
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
类裂隙{
公众:
向量*shufflePile(){
向量*桩=新向量;
对于(int i=0;i push_back(i));
}
srand(_Seed;未签名(time(_time0));
随机洗牌(堆->开始(),堆->结束());
}
};
类别CDOMINES{
整件[28][3]=
{
{0,0,1}, //1
{1,1,1}, {1,0,1}, //2,3
{2,2,1}, {2,1,1}, {2,0,1}, //4, 5, 6
{3,3,1}, {3,2,1}, {3,1,1}, {3,0,1}, //7, 8, 9, 10
{4,4,1}, {4,3,1}, {4,2,1}, {4,1,1}, {4,0,1}, //11, 12, 13, 14, 15
{5,5,1}, {5,4,1}, {5,3,1}, {5,2,1}, {5,1,1}, {5,0,1}, //16, 17,18, 19, 20, 21
{6,6,1}, {6,5,1}, {6,4,1}, {6,3,1}, {6,2,1}, {6,1,1}, {6,0,1} //22, 23, 24, 25, 26, 27, 28 
};
};
类CPlayer{
};
类CTable{
};
int main(){
}
而不是

srand(_Seed;unsigned(time(_time0));
做:-

srand(时间(0));
在整个计划中只做一次


此在现代C++中不推荐使用,而是在标准库头中看到<代码>随机< /> > .< /p>推荐:在<代码> vector *Suffle()<代码>按值返回<代码>向量。现代C++有很多技巧来消除复制开销,而你必须通过消除管理自己的分配来获益。边注:看看这个结尾的例子。可能给你一些想法。对于一个改组算法,使用适合你的数组。这是C++,所以避免
rand
/
srand
。使用
标题中提供的工具。这里有一个链接,指向一个很好的演示文稿,介绍为什么您应该选择较新的随机数工具,以及一个关于如何使用它们的优秀教程:。