Différences entre les versions de « EASEA defined functions »

De
Aller à la navigation Aller à la recherche
 
(5 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
 
= Random Number Generators =
 
= Random Number Generators =
  
== TossCoin ==
+
== tossCoin ==
  
 
=== Description ===
 
=== Description ===
  
Simulates the toss of a coin. There are two different definitions of the tossCoin function:
+
Simulates a (possibly biased) toss of a coin.
#A simple toss of a coin.
 
#A biased toss of a coin.
 
  
 
=== EASEA syntax ===
 
=== EASEA syntax ===
  
  bool tossCoin()               // SImple tosscoin
+
  bool tossCoin()   // returns true with probability .5
  
  bool tossCoin(float bias)  // Biased tossCoin
+
  bool tossCoin(fBias)  // returns true with probability fBias, with fBias in [0,1]
  
=== Example ===
+
=== tossCoin Example ===
  
  if( tossCoin(0.1)){
+
  if (tossCoin(.1)){ // 10% chance to execute this code
 
     ...
 
     ...
 
  }
 
  }
Ligne 25 : Ligne 23 :
 
=== Description ===
 
=== Description ===
  
Generates a random number. There are several definitions to the random function:
+
Generates a random number:
#Random function with Min Max Boundary
+
* Using a Mersenne twister v2 in easea versions up to ???
#Random function with Max Boundary only
+
* Using a ??? in easea versions after ???
In the case of a Max boundary only, the Min boundary will be 0.
+
 +
The [[EASEA defined functions#random|random]] function is overloaded:
 +
* Without any arguments, <code>random()</code> returns a float in [0,1[ '''(1 excluded)'''. For consistency reasons, this behaviour (excluding the upper value) applies in all cases described below '''(so <code>random(0,1)</code> only returns 0)'''.
 +
* With only one argument, <code>random(arg)</code> will return a value between 0 and the value of its argument '''(excluded)''': [0,arg[.
 +
* With two arguments, <code>random(arg1,arg2)</code> will return a value between <code>arg1</code> and <code>arg1</code> '''(excluded)''': [arg1,arg2[.
  
 +
The type of the returned value is the same as the type of the arguments.
 
=== EASEA syntax ===
 
=== EASEA syntax ===
  int random( int Min, int Max)
+
  int random()
  
  int random( int Max)
+
  int random(int nMax)
  
  float random( float Min, float Max)
+
  float random(float fMax)
  
  double random( double Min, double Max)
+
  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

Version actuelle datée du 1 juin 2020 à 03:39

Random Number Generators

tossCoin

Description

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

Random

Description

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