![]() |
naev 0.12.5
|
Lua bindings for the Naev random number generator. More...
#include "nlua_rnd.h"#include "nluadef.h"#include "rng.h"
Go to the source code of this file.
Functions | |
| static int | rndL_int (lua_State *L) |
| Bindings for interacting with the random number generator. | |
| static int | rndL_sigma (lua_State *L) |
| Creates a number in the one-sigma range [-1:1]. | |
| static int | rndL_twosigma (lua_State *L) |
| Creates a number in the two-sigma range [-2:2]. | |
| static int | rndL_threesigma (lua_State *L) |
| Creates a number in the three-sigma range [-3:3]. | |
| static int | rndL_uniform (lua_State *L) |
| Gets a random number in the given range, with a uniform distribution. | |
| static int | rndL_angle (lua_State *L) |
| Gets a random angle, i.e., a random number from 0 to 2*pi. | |
| static int | rndL_permutation (lua_State *L) |
| Creates a random permutation. | |
| int | nlua_loadRnd (nlua_env env) |
| Loads the Random Number Lua library. | |
Variables | |
| static const luaL_Reg | rnd_methods [] |
Lua bindings for the Naev random number generator.
Definition in file nlua_rnd.c.
| int nlua_loadRnd | ( | nlua_env | env | ) |
Loads the Random Number Lua library.
| env | Lua environment. |
Definition at line 43 of file nlua_rnd.c.
|
static |
Gets a random angle, i.e., a random number from 0 to 2*pi.
Lua usage parameter: vec2.newP(radius, rnd.angle()) Lua return parameter: number A randomly generated angle, in radians.
| L | Lua State |
Lua function: angle
Definition at line 202 of file nlua_rnd.c.
|
static |
Bindings for interacting with the random number generator.
This module not only allows basic random number generation, but it also handles more complicated statistical stuff.
Example usage would be:
Lua module: rnd
Gets a random number. With no parameters it returns a random float between 0 and 1.
With one parameter it returns a whole number between 0 and that number (both included). With two parameters it returns a whole number between both parameters (both included).
Lua usage parameter: n = rnd() – Number in range [0:1]. Lua usage parameter: n = rnd(5) – Number in range [0:5]. Lua usage parameter: n = rnd(3,5) – Number in range [3,5].
Lua function parameter: number x First parameter, read description for details. Lua function parameter: number y Second parameter, read description for details. Lua return parameter: number A randomly generated number, read description for details.
| L | Lua State |
Lua function: rnd
Definition at line 84 of file nlua_rnd.c.
|
static |
Creates a random permutation.
This creates a list from 1 to input and then randomly permutates it, however, if an ordered table is passed as a parameter, that is randomly permuted instead.
Lua usage parameter: t = rnd.permutation( 5 ) Lua usage parameter: t = rnd.permutation( {"cat", "dog", "cheese"} )
Lua function parameter: number|table input Maximum value to permutate to. Lua return parameter: table A randomly permutated table.
| L | Lua State |
Lua function: permutation
Definition at line 222 of file nlua_rnd.c.
|
static |
Creates a number in the one-sigma range [-1:1].
A one sigma range means that it creates a number following the normal distribution but limited to the 63% quadrant. This means that the number is biased towards 0, but can become either 1 or -1. It's a fancier way of generating random numbers.
Lua usage parameter: n = 5.5 + rnd.sigma()/2. – Creates a number from 5 to 6 slightly biased to 5.5. Lua return parameter: number A number from [-1:1] biased slightly towards 0.
| L | Lua State |
Lua function: sigma
Definition at line 117 of file nlua_rnd.c.
|
static |
Creates a number in the three-sigma range [-3:3].
This function behaves much like its brothers rnd.sigma and rnd.twosigma. The main difference is that it uses the three-sigma range which is the 99% quadrant. It will rarely generate numbers outside the [-2:2] range (about 5% of the time) and create numbers outside of the [-1:1] range about 37% of the time. This can be used when you want extremes to appear rarely.
Lua usage parameter: n = 5.5 + rnd.threesigma()/6. – Creates a number from 5 to 6 totally biased to 5.5.
Lua return parameter: number A number from [-3:3] biased totally towards 0.
| L | Lua State |
Lua function: threesigma
Definition at line 156 of file nlua_rnd.c.
|
static |
Creates a number in the two-sigma range [-2:2].
This function behaves much like the rnd.sigma function but uses the two-sigma range, meaning that numbers are in the 95% quadrant and thus are much more random. They are biased towards 0 and approximately 63% will be within [-1:1]. The rest will be in either the [-2:-1] range or the [1:2] range.
Lua usage parameter: n = 5.5 + rnd.twosigma()/4. – Creates a number from 5 to 6 heavily biased to 5.5.
Lua return parameter: number A number from [-2:2] biased heavily towards 0.
| L | Lua State |
Lua function: twosigma
Definition at line 136 of file nlua_rnd.c.
|
static |
Gets a random number in the given range, with a uniform distribution.
Lua usage parameter: n = uniform() – Real number in the interval [0,1]. Lua usage parameter: n = uniform(5) – Real number in the interval [0,5]. Lua usage parameter: n = uniform(3,5) – Real number in the interval [3,5].
Lua function parameter: number x First parameter, read description for details. Lua function parameter: number y Second parameter, read description for details. Lua return parameter: number A randomly generated number, read description for details.
| L | Lua State |
Lua function: uniform
Definition at line 175 of file nlua_rnd.c.
|
static |
Random Lua methods.
Definition at line 28 of file nlua_rnd.c.