v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | List of all members
Sifteo::Random Struct Reference

Pseudo-random number generator. More...

#include <sifteo/math.h>

Public Member Functions

bool chance (float probability)
 Take a chance. Returns a boolean that has a 'probability' chance of being 'true'. More...
 
float expovariate (float averageInterval)
 Returns a generated pseudorandom inverval for a poisson process (e.g. whack-a-mole timing).
 
template<typename T >
randint (T a, T b)
 Returns a uniformly distributed random integer in the range [a, b], including both end points.
 
 Random ()
 Construct a new random number generator, using an arbitrary seed.
 
 Random (uint32_t s)
 Construct a new random number generator with a well-defined seed.
 
float random ()
 Returns a uniformly distributed floating point number between 0 and 1, inclusive.
 
template<typename T >
randrange (T a, T b)
 Returns a uniformly distributed random integer in the half-open interval [a, b), including the lower but not the upper end point.
 
template<typename T >
randrange (T count)
 The one-argument variant of randrange() always starts at zero, and returns an integer up to but not including 'count'. More...
 
uint32_t raw ()
 Returns the next raw 32-bit pseudo-random number.
 
void seed (uint32_t s)
 Re-seed this random number generator. More...
 
void seed ()
 Re-seed this random number generator arbitrarily. More...
 
float uniform (float a, float b)
 Returns a uniformly distributed floating point number in the range [a, b) or [a, b], depending on rounding.
 

Detailed Description

Pseudo-random number generator.

Each instance of the Random class has a distinct PRNG state.

When possible, method semantics here have been designed to match those used by Python's "random" module.

Member Function Documentation

bool Sifteo::Random::chance ( float  probability)
inline

Take a chance. Returns a boolean that has a 'probability' chance of being 'true'.

If the argument is constant, all floating point math folds away at compile-time. For values of 0 and 1, we are guaranteed to always return false or true, respectively.

template<typename T >
T Sifteo::Random::randrange ( count)
inline

The one-argument variant of randrange() always starts at zero, and returns an integer up to but not including 'count'.

Guaranteed to be capable of returning 'count' distinct values, starting at zero.

void Sifteo::Random::seed ( uint32_t  s)
inline

Re-seed this random number generator.

For a given seed, the subsequent random numbers are guaranteed to be deterministic.

void Sifteo::Random::seed ( )
inline

Re-seed this random number generator arbitrarily.

This implementation uses the system's nanosecond timer.


The documentation for this struct was generated from the following file: