Every time I open my game, a function that should be generating RANDOM numbers is generating the same combination of numbers EVERY TIME. Here's the code to my randomizing function that randomizes the list:
function tRandom(t)
local values = {}
for i=1, #t do
local n = #values+1
table.insert(values,math.random(n),t[i])
end
return values
end
town = tRandom({1,2,3,4,5,6,7,8})
I'm not sure if it's just my problem, but this is going to be a major snag in my game development, and I need it fixed. Is there any solution?
static int lua_random (lua_State* L) {
int l=lua_tointeger(L,1);
int h=lua_tointeger(L,2);
int r=rand(); //standard C rand function. Comes with math library
if (r!=NULL && h!=NULL)
lua_pushnumber(L,(lua_Number)l+floor(h*r)); // floor is also a C function in math.h, I think
else
lua_pushnumber(L,(lua_Number) r);
return 1;
}