From 2f22c6bb79d209a55b3fc8e0b2d9c9f89f038174 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 19 Jul 2019 13:31:53 -0300 Subject: 'math.randomseed' always returns the two seed components --- lmathlib.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lmathlib.c') diff --git a/lmathlib.c b/lmathlib.c index 1d310b2d..752647e7 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -586,7 +586,8 @@ static int math_random (lua_State *L) { } -static void setseed (Rand64 *state, lua_Unsigned n1, lua_Unsigned n2) { +static void setseed (lua_State *L, Rand64 *state, + lua_Unsigned n1, lua_Unsigned n2) { int i; state[0] = Int2I(n1); state[1] = Int2I(0xff); /* avoid a zero state */ @@ -594,6 +595,8 @@ static void setseed (Rand64 *state, lua_Unsigned n1, lua_Unsigned n2) { state[3] = Int2I(0); for (i = 0; i < 16; i++) nextrand(state); /* discard initial values to "spread" seed */ + lua_pushinteger(L, n1); + lua_pushinteger(L, n2); } @@ -605,9 +608,7 @@ static void setseed (Rand64 *state, lua_Unsigned n1, lua_Unsigned n2) { static void randseed (lua_State *L, RanState *state) { lua_Unsigned seed1 = (lua_Unsigned)time(NULL); lua_Unsigned seed2 = (lua_Unsigned)(size_t)L; - lua_pushinteger(L, seed1); - lua_pushinteger(L, seed2); - setseed(state->s, seed1, seed2); + setseed(L, state->s, seed1, seed2); } @@ -615,14 +616,13 @@ static int math_randomseed (lua_State *L) { RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1)); if (lua_isnone(L, 1)) { randseed(L, state); - return 2; /* return seeds */ } else { lua_Integer n1 = luaL_checkinteger(L, 1); lua_Integer n2 = luaL_optinteger(L, 2, 0); - setseed(state->s, n1, n2); - return 0; + setseed(L, state->s, n1, n2); } + return 2; /* return seeds */ } -- cgit v1.2.3-55-g6feb