'math.randomseed' always returns the two seed components
diff --git a/lmathlib.c b/lmathlib.c
index 1d310b2..752647e 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -586,7 +586,8 @@
 }
 
 
-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 @@
   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 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 @@
   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 */
 }
 
 
diff --git a/manual/manual.of b/manual/manual.of
index 7f2596f..1646f11 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -7798,8 +7798,10 @@
 When called with no arguments,
 Lua generates a seed with
 a weak attempt for randomness.
-In this case,
-the call returns the two seed components that were used.
+
+This function returns the two seed components
+that were effectively used,
+so that setting them again repeats the sequence.
 
 To ensure a required level of randomness to the initial state
 (or contrarily, to have a deterministic sequence,
diff --git a/testes/math.lua b/testes/math.lua
index 0c297e7..d0aaa6a 100644
--- a/testes/math.lua
+++ b/testes/math.lua
@@ -842,9 +842,11 @@
 
 do
   -- testing return of 'randomseed'
-  local <const> x, <const> y = math.randomseed()
+  local x, y = math.randomseed()
   local res = math.random(0)
-  math.randomseed(x, y)    -- should repeat the state
+  x, y = math.randomseed(x, y)    -- should repeat the state
+  assert(math.random(0) == res)
+  math.randomseed(x, y)    -- again should repeat the state
   assert(math.random(0) == res)
   -- keep the random seed for following tests
 end