产生特定区间随机数(整型和浮点型)的静态类方法
//!随机数的最大值
#define ARC4RANDOM_MAX 0x100000000
+ (NSInteger)createRandomsizeValueInt:(NSInteger)fromInt toInt:(NSInteger)toInt
{
if (toInt < fromInt)
{
return toInt;
}
if (toInt == fromInt)
{
return fromInt;
}
NSInteger randVal = arc4random() % (toInt - fromInt + 1) + fromInt;
return randVal;
}
+ (double)createRandomsizeValueFloat:(double)fromFloat toFloat:(double)toFloat
{
if (toFloat < fromFloat)
{
return toFloat;
}
if (toFloat == fromFloat)
{
return fromFloat;
}
double randVal = ((double)arc4random() / ARC4RANDOM_MAX) * (toFloat - fromFloat) + fromFloat;
return randVal;
}