⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dice6.cpp

📁 用vc++开发的一个经典程序:Dice。自己开发的
💻 CPP
字号:
#include "StdAfx.h"
#include ".\dice6.h"
//#include <stdlib.h>
#include <math.h>
//#include <stdio.h>  //for srant()
#include <time.h>	//for srant()

//##ModelId=4507556B013B
Dice6::Dice6(void)
: diceNum(1)
, availability(true)
{
}

//##ModelId=4507556B013D
Dice6::~Dice6(void)
{
}

//##ModelId=4507556B0146
int Dice6::generateNum(void)
{	
	//srand( (unsigned)time( NULL ) );
	long seed=(long)time(NULL);
	int num=(int (Crand(& seed)*100))%6 + 1;	//There is a problem about the num.
	diceNum=num;
	return num;
}

//##ModelId=4507556B0148
void Dice6::setAvailability(bool avail)
{
	availability=avail;
}

//##ModelId=4507556B0150
bool Dice6::getAvailability(void)
{
	return availability;
}

//##ModelId=4507556B0152
int Dice6::getNum(void)
{
	return diceNum;
}

//##ModelId=4507556B0154
double Dice6::Crand(long *seed)//生成[0,1]平稳分布随机数。
{
	const long int MBIG=0x0fffffff;
	const long int MSEED=0x03c04ffd;
	const int MZ=0;
	const double FAC=1.0/MBIG;
	static int inext,inextp,iff=0;
	static long ma[56],mj,mk;
	int i,j,k;
	if(*seed<0 || iff==0)
	{
	iff=1;
	mj=MSEED-(*seed<0? -*seed:*seed);
	mj%=MBIG;
	ma[55]=mj;
	for(mk=1,i=1;i<=54;i++)
	{
	j=(21*i)%55;
	ma[j]=mk;
	mk=mj-mk;
	if(mk<MZ) mk+=MBIG;
	mj=ma[j];
	}
	for(k=1;k<=4;k++)
	for(i=1;i<=55;i++)
	{
	ma[i]-=ma[1+(i+30)%55];
	if(ma[i]<MZ) ma[i]+=MBIG;
	}
	inext=0;
	inextp=31;
	*seed=1;
	}
	if(++inext==56) inext=1;
	if(++inextp==56) inextp=1;
	mj=ma[inext]-ma[inextp];
	if(mj<MZ) mj+=MBIG;
	ma[inext]=mj;
	return mj*FAC;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -