Jump to content
Sign in to follow this  
Conde2

Tópico das Funções !!

Recommended Posts

Conde2    0
Conde2

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 by Conde2

Share this post


Link to post
Share on other sites
Notorious    1
Notorious

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.

arairai.png

Edited by Mickfern

Share this post


Link to post
Share on other sites
Gpwjhlkdcf    21
Gpwjhlkdcf

function table.remove(t, p)
 t[p] = nil
 return true
end

.__.'

Edited by Mickfern

Share this post


Link to post
Share on other sites
Notorious    1
Notorious

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 by Mickfern

Share this post


Link to post
Share on other sites
pejuge2    1
pejuge2

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 by pejuge2

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×