24,854
社区成员
发帖
与我相关
我的任务
分享
void Poker::initRandomArry()
{
for(int n=0;n<=28;n++) //init arry
{
pokerArry[n] = 0;
}
srand((unsigned)GetTickCount());
for(int m = 1;m<= 28;m++)//这是要放入的28个整型数
{
int a= (int)27 * rand()/32767+1; //随机产生位置
if(pokerArry[a]==0) //判断此位置是否为空
{
pokerArry[a]=m; //空,放入其中
}
else //不空
{
for(int n=1;n<=28;n++) //比较所有数组空间
{
if(pokerArry[n]==0) //找到空闲的位置
{
pokerArry[n]=m; //放入其中
break;
}
}//end for
}// end if
} //end for
#include <iostream>
#include <ctime>
#include <cmath>
void A::Ain::print() {
std::cout << "Print of Ain." << std::endl;
}
int main() {
srand(time(0));
const int max = 28;
for (int i = 0; i < 20; i++) {
int temp = rand() % max + 1; // 结果是1到max(包括1与max)之间.
std::cout << temp << std::endl;
}
return 0;
}