/* This function uses 'double' (instead of 'lua_Number') to ensure that all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0' will keep full precision (ensuring that 'r' is always less than 1.0.)  */
static int math_random(lua_State *L)
/* This function uses 'double' (instead of 'lua_Number') to ensure that all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0' will keep full precision (ensuring that 'r' is always less than 1.0.)  */
static int math_random(lua_State *L)
{
    case 0: {
      lua_pushnumber(L, (lua_Number)r);
      return 1;
    }
    case 1: {
      low = 1;
      up = luaL_checkinteger(L, 1);
      break;
    }
    case 2: {
      low = luaL_checkinteger(L, 1);
      up = luaL_checkinteger(L, 2);
      break;
    }
    default: return luaL_error(L, "wrong number of arguments");
  }
  luaL_argcheck(L, low <= up, 1, "interval is empty");
  luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1,
                   "interval too large");
  r *= (double)(up - low) + 1.0;
  lua_pushinteger(L, (lua_Integer)r + low);
  return 1;
}