cocos2d中生成随机数

前端之家收集整理的这篇文章主要介绍了cocos2d中生成随机数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<span style="background-color: rgb(0,153);">
</span>
<span style="background-color: rgb(204,204,204);">#include "<span style="font-family:Arial Black;">cocos2d</span>.h"</span>
<span style="background-color: rgb(204,204);">USING_NS_CC;//名称控件不可少</span>
<span style="background-color: rgb(204,204);">int MyRandom(int min,int max)
{
	struct tm*tm;
	time_t timP;
	if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	{
		time(&timP);
	}
	else
	{
		struct timeval tv;

		gettimeofday(&tv,NULL);</span>
<span style="background-color: rgb(204,204);">		timP = tv.tv_sec;
	}
	tm = localtime(&timP);
	int Sencond = tm->tm_sec;
	return (((int)(CCRANDOM_0_1() * 1000) + Sencond) % (max-min) + min);

}</span>

猜你在找的Cocos2d-x相关文章