EASEA defined functions

Aller à : navigation, rechercher

Random Number Generators



Simulates a (possibly biased) toss of a coin.

EASEA syntax

bool tossCoin()   // returns true with probability .5
bool tossCoin(fBias)  // returns true with probability fBias, with fBias in [0,1]

tossCoin Example

if (tossCoin(.1)){ // 10% chance to execute this code



Generates a random number:

  • Using a Mersenne twister v2 in easea versions up to ???
  • Using a ??? in easea versions after ???

The random function is overloaded:

  • Without any arguments, random() returns a float in [0,1[ (1 excluded). For consistency reasons, this behaviour (excluding the upper value) applies in all cases described below (so random(0,1) only returns 0).
  • With only one argument, random(arg) will return a value between 0 and the value of its argument (excluded): [0,arg[.
  • With two arguments, random(arg1,arg2) will return a value between arg1 and arg1 (excluded): [arg1,arg2[.

The type of the returned value is the same as the type of the arguments.

EASEA syntax

int random()
int random(int nMax)
float random(float fMax)
double random(double dMax)
int random(int nMin, int nMax)
float random(float fMin, float fMax)
double random(double dMin, double dMax)

random Examples

random(); // returns a float in [0.,1.[ = up to 0.999999...
random(1); // returns... 0
random(2); // randomly returns values 0 or 1
random(0,1); // returns... 0
random(0,2); // randomly returns values 0 or 1
random(-3.2,5.0); // randomly returns values in [-3.2,5.0[ 5.0 excluded