91 int o = lua_gettop(L);
94 lua_pushnumber(L, RNGF() );
96 l = luaL_checkint(L,1);
97 lua_pushnumber(L, RNG(0, l));
100 l = luaL_checkint(L,1);
101 h = luaL_checkint(L,2);
102 lua_pushnumber(L, RNG(l,h));
105 NLUA_INVALID_PARAMETER(L,1);
122 lua_pushnumber(L, RNG_1SIGMA());
140 lua_pushnumber(L, RNG_2SIGMA());
159 lua_pushnumber(L, RNG_3SIGMA());
177 int o = lua_gettop( L );
180 lua_pushnumber( L, RNGF() );
182 int l = luaL_checknumber( L, 1 );
183 lua_pushnumber( L, RNGF() * l );
186 int l = luaL_checknumber( L, 1 );
187 int h = luaL_checknumber( L, 2 );
188 lua_pushnumber( L, l + (h-l) * RNGF() );
191 NLUA_INVALID_PARAMETER(L,1);
205 lua_pushnumber( L, RNGF() * 2. * M_PI );
229 if (lua_isnumber(L,1)) {
230 max = lua_tointeger(L,1);
233 else if (lua_istable(L,1)) {
234 max = (int) lua_objlen(L,1);
238 NLUA_INVALID_PARAMETER(L,1);
241 values = malloc(
sizeof(
int)*max );
242 for (
int i=0; i<max; i++)
246 for (
int i = max-1; i >= 0; --i){
251 int temp = values[i];
252 values[i] = values[j];
258 for (
int i=0; i<max; i++) {
259 lua_pushnumber( L, values[i]+1 );
261 lua_gettable( L, 1 );
262 lua_rawseti( L, -2, i+1 );
Header file with generic functions and naev-specifics.
static int rndL_twosigma(lua_State *L)
Creates a number in the two-sigma range [-2:2].
static int rndL_angle(lua_State *L)
Gets a random angle, i.e., a random number from 0 to 2*pi.
static int rndL_sigma(lua_State *L)
Creates a number in the one-sigma range [-1:1].
static int rndL_threesigma(lua_State *L)
Creates a number in the three-sigma range [-3:3].
int nlua_loadRnd(nlua_env env)
Loads the Random Number Lua library.
static int rndL_permutation(lua_State *L)
Creates a random permutation.
static int rndL_uniform(lua_State *L)
Gets a random number in the given range, with a uniform distribution.
static int rndL_int(lua_State *L)
Bindings for interacting with the random number generator.
static const luaL_Reg rnd_methods[]
unsigned int randint(void)
Gets a random integer.