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;
}

你可能感兴趣的:(cocos2dx)