Conde2 0 #41 Posted October 15, 2009 (edited) Vejam o que saiu no meu math.random =/ Eu usei a função do Skyen como base e tentei por um seed para rondomizar =D Usei o os.time() e os.clock() como o mock falou. E ta ai o que deu: function math.randoma(min, max) if min >= max then print("Interval is empty.") return end var = "" .. os.time() varr = "".. os.clock() if max > 99 then x = -3 elseif max > 9 then x = -2 else x = -1 end tn = tonumber(string.sub(var,x,-1)) sus = tonumber(string.sub(varr,x,-1)) if max < 10 then sus = 1 end last = ((min-max)*(last or 2000)-1)%((max-min+1)*97531) result = math.floor((last+min)/97531)+tn while max <= result do result = result - sus end while min >= result do result = result + sus end return result end OBS: no meu de certinho mais quando eu pedi pro skyen e o mock testar deu diferente deve ser porcausa do os.clock e os.time então tem que ajusatar ainda =/ Edited October 15, 2009 by Conde2 Share this post Link to post Share on other sites
Notorious 1 #42 Posted November 21, 2009 (edited) Refiz o table.concat, porém mudei alguns argumentos, adicionei o f, que é com o que a string termina, exemplo: 1, 3, 4. function table.concat_(table, sep, f) for a = 1, #table do str = (str or "") .. table[a] .. (a ~= #table and sep or f) end return str end Dava pra diminuir muitos codes aqui do tópico usando o or. Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #43 Posted November 21, 2009 (edited) function table.remove(t, p) t[p] = nil return true end .__.' Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Notorious 1 #44 Posted November 21, 2009 (edited) Aprimorei o table.concat_, agora com o "i" e "j" ... Valeu manoloks. function table.concat_(table, sep, i, j) for a = i or 1, j or #table do str = (str or "") .. table[a] .. ( a ~= j and a ~= #table and sep or "" ) end return str end Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
pejuge2 1 #45 Posted March 3, 2010 (edited) Refiz a função table.insert. Talvez tenha um ou dois POGzinhos mas tá não faz mal uhauh.! function table.insertn(t, n, v) local r = {} if n then for all = 1, n - 1 do r[all] = t[all] end end for all = n or 1, #t do r[all + 1] = t[all] end r[n or 1] = v for all = 1, #r do t[all] = r[all] end return true end Edited March 3, 2010 by pejuge2 Share this post Link to post Share on other sites