87 int o = lua_gettop( L );
90 lua_pushnumber( L, RNGF() );
92 l = luaL_checkint( L, 1 );
93 lua_pushnumber( L, RNG( 0, l ) );
94 }
else if ( o >= 2 ) {
95 l = luaL_checkint( L, 1 );
96 h = luaL_checkint( L, 2 );
97 lua_pushnumber( L, RNG( l, h ) );
99 NLUA_INVALID_PARAMETER( L, 1 );
119 lua_pushnumber( L, RNG_1SIGMA() );
138 lua_pushnumber( L, RNG_2SIGMA() );
158 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 );
184 }
else if ( o >= 2 ) {
185 int l = luaL_checknumber( L, 1 );
186 int h = luaL_checknumber( L, 2 );
187 lua_pushnumber( L, l + ( h - l ) * RNGF() );
189 NLUA_INVALID_PARAMETER( L, 1 );
204 lua_pushnumber( L, RNGF() * 2. * M_PI );
228 if ( lua_isnumber( L, 1 ) ) {
229 max = lua_tointeger( L, 1 );
231 }
else if ( lua_istable( L, 1 ) ) {
232 max = (int)lua_objlen( L, 1 );
235 NLUA_INVALID_PARAMETER( L, 1 );
238 values = malloc(
sizeof(
int ) * max );
239 for (
int i = 0; i < max; i++ )
243 for (
int i = max - 1; i >= 0; --i ) {
248 int temp = values[i];
249 values[i] = values[j];
255 for (
int i = 0; i < max; i++ ) {
256 lua_pushnumber( L, values[i] + 1 );
258 lua_gettable( L, 1 );
259 lua_rawseti( L, -2, i + 1 );
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.