// 抽奖.cpp : 定义控制台应用程序的入口点。
//
include “stdafx.h”
include
include
include
using namespace std;
/*****************
中奖描述:
一等奖(A): 10 权重
二等奖(B): 20 权重
三等奖(C): 200 权重
四等奖(D): 800 权重
*********************/
enum EM_QuanZ
{
EM_A = 10,
EM_B = 20,
EM_C = 170,
EM_D = 800
};
int Bigrand()
{
//随机数列一般由srand()和rand()共同设置,从而得到真正意义上的随机
//设置随机种子
srand((unsigned)time(NULL));
return RAND_MAX*rand() + rand();
}
int a[4] = {0};
int GetRanDomKey()
{
//获取随机数
int number = (Bigrand() % (EM_A + EM_B + EM_C + EM_D)) + 1;
if ((number > 0) && (number <= EM_A))
{
number = 1;
++a[0];
}
else if (number >= (EM_A + EM_B + EM_C))
{
number = 4;
++a[3];
}
else if ((number >= (EM_A + EM_B)) && (number < (EM_A + EM_B + EM_C)))
{
number = 3;
++a[2];
}
else if ((number >= EM_A) && (number < (EM_A + EM_B)))
{
number = 2;
++a[1];
}
return number;
}
void GetAward(int key)
{
cout << “恭喜您中了” << key<<”等奖” << endl;
}
void Start()
{
while (true)
{
GetAward(GetRanDomKey());
int number = (rand() % 10) + 1;
if ((a[0]+a[1]+a[2]+a[3]) == 100)
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
std::thread td(Start);
td.join();
for (int i = 0; i < 4; i++)
{
cout <<i+1 <<"等奖中奖次数: " << a[i] << endl;
}
system("pause");
return 0;
}