PXMath Class Reference
| Inherits from | NSObject |
| Declared in | PXMath.h PXMath.m |
Overview
Contains static methods for computing random values.
The PXMath class does not implement methods for general mathematical
operations such as sin, cos, abs, sqrt, etc., but
instead is concentrated on dealing with random number generation.
It is recommended to use the native C methods and Macros for common math
operations such as sqrtf(), sinf(), atan2f(), etc..
Tasks
-
+ randomReturns a pseudo-random number, where 0.0f <= number < 1.0f.
-
+ seedRandomWithValue:Sets the seed for random number generation with the specified value. Useful in cases where a reproducible set of psuedo-random numbers is required.
-
+ randomFloatInRangeFrom:to:Returns a pseudo-random number, where min <= number < max. Due to the way floating points work, the max value is possible under certain circumstances; such as the min being 0.00001f and the max being 0.00002f. However this is still unlikely, and in the general use case it will never be equal to the max.
-
+ randomIntInRangeFrom:to:Returns a pseudo-random number, where min <= number <= max.
-
+ seedRandomWithTimeSets the seed for random number generation based on the current time. This method gets called automatically when the Pixelwave engine is initialized.
Class Methods
random
Returns a pseudo-random number, where 0.0f <= number < 1.0f.
+ (float)randomReturn Value
A pseudo-random number.
Example:
float randomValue = [PXMath random];
//0.0f <= randomValue < 1.0f
Declared In
PXMath.mrandomFloatInRangeFrom:to:
Returns a pseudo-random number, where min <= number < max. Due to the way floating points work, the max value is possible under certain circumstances; such as the min being 0.00001f and the max being 0.00002f. However this is still unlikely, and in the general use case it will never be equal to the max.
+ (float)randomFloatInRangeFrom:(float)min to:(float)maxReturn Value
A pseudo-random number.
Example:
float randomValue = [PXMath randomFloatInRangeWithMin:3.0f max:4.5f];
//3.0f <= randomValue < 4.5f
Declared In
PXMath.mrandomIntInRangeFrom:to:
Returns a pseudo-random number, where min <= number <= max.
+ (int)randomIntInRangeFrom:(int)min to:(int)maxReturn Value
A pseudo-random number.
Example:
int randomValue = [PXMath randomIntInRangeWithMin:3 max:5];
//3 <= randomValue <= 5, randomValue will be either 3, 4 or 5.
Declared In
PXMath.m