cocos2dx 随机数

int型随机数:
#include <ctime>
#include <cmath>
int randomBetweenInt(int max, int min)
{
    time_t t;
    std::srand((unsigned int)time(&t));//随机数种子
    return std::rand() % (max - min) + min;
}


float型随机数:
float randomBetweenFloat(float min, float max) 
{
    return (2.0f*random() / 0xFFFFFFFFu) * (max - min) + min;
}

猜你喜欢

转载自zhuangshuo.iteye.com/blog/1874678
今日推荐