Différences entre les versions de « EASEA defined functions »
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 == |
=== Description === | === Description === | ||
− | Simulates | + | Simulates a (possibly biased) toss of a coin. |
− | |||
− | |||
=== EASEA syntax === | === EASEA syntax === | ||
− | bool tossCoin() | + | bool tossCoin() // returns true with probability .5 |
− | bool tossCoin( | + | bool tossCoin(fBias) // returns true with probability fBias, with fBias in [0,1] |
− | === Example === | + | === tossCoin Example === |
− | if( tossCoin( | + | if (tossCoin(.1)){ // 10% chance to execute this code |
... | ... | ||
} | } | ||
Ligne 25 : | Ligne 23 : | ||
=== Description === | === Description === | ||
− | Generates a random number | + | Generates a random number: |
− | + | * Using a Mersenne twister v2 in easea versions up to ??? | |
− | + | * Using a ??? in easea versions after ??? | |
− | + | ||
+ | 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 random() |
− | int random( int | + | int random(int nMax) |
− | float random( float | + | float random(float fMax) |
− | double random( double | + | 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 (sorandom(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 betweenarg1
andarg1
(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