lottoryutils.cpp
来自「完成抽奖的基本功能。可以载入文本文件」· C++ 代码 · 共 58 行
CPP
58 行
// LottoryUtils.cpp: implementation of the LottoryUtils class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "WinLottory.h"
#include "LottoryUtils.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LottoryUtils::LottoryUtils()
{
}
LottoryUtils::~LottoryUtils()
{
}
void LottoryUtils::getRand(int* result,int maxnum,int num)
{
int aResult;
srand((unsigned)time(NULL));
for(int i=0;i<num;i++)
{
//result=1+(int)(10.0*rand()/(maxnum+1.0));
while(true)
{
bool flag = true;
aResult = rand()%maxnum;
for(int j=0;j<i;j++)
{
if (aResult==result[j])
{
flag = false;
printf("same one!\n");
}
}
if (flag == true)
{
result[i]=aResult;
break;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?