File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ static uint64_t next() {
3535
3636#define MT64_MUL (1.0 / 9007199254740992.0 )
3737
38+ static double next_double (void ) {
39+ return (double )(next () >> 11 ) * MT64_MUL;
40+ }
41+
3842static uint64_t bounded_rand (uint64_t n) {
3943 uint64_t r = next ();
4044 return r % n;
@@ -44,7 +48,7 @@ static int Random(lua_State *L) {
4448 lua_Integer low, up;
4549 switch (lua_gettop (L)) { /* check number of arguments */
4650 case 0 : { /* no arguments */
47- double r = ( double )( next () >> 11 ) * MT64_MUL ;
51+ double r = next_double () ;
4852 lua_pushnumber (L, (lua_Number)r); /* Number between 0 and 1 */
4953 return 1 ;
5054 }
@@ -142,7 +146,7 @@ static int WeightedChoice(lua_State *L) {
142146 if (sum == 0 ) {
143147 return luaL_error (L, " all weights are zero" );
144148 }
145- lua_Number rnd = ( double )( next () >> 11 ) * MT64_MUL * sum;
149+ lua_Number rnd = next_double () * sum;
146150 lua_pushnil (L);
147151 while (lua_next (L, 1 ) != 0 ) {
148152 lua_Number w = lua_tonumber (L, -1 );
You can’t perform that action at this time.
0 commit comments