Code: Select all
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})
Code: Select all
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})
TechnoCat wrote:You should be setting a random seed before you generate random numbers.
Code: Select all
math.randomseed( os.time() )
Code: Select all
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;
}
Problem solved. Thanksleiradel wrote:TechnoCat wrote:You should be setting a random seed before you generate random numbers.Also, math.random uses libc's rand which isn't very good on some system though for many games it will do well.Code: Select all
math.randomseed( os.time() )
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 197 guests