Line 1: |
Line 1: |
| + | -- [[Category:Net modules]] |
| + | |
| local p = {} | | local p = {} |
| | | |
Line 13: |
Line 15: |
| end | | end |
| return true | | return true |
| + | end |
| + | |
| + | function table.getKeys(self) |
| + | local keys = {} |
| + | for k,_ in pairs(self) do |
| + | table.insert(keys,k) |
| + | end |
| + | return keys |
| + | end |
| + | |
| + | function table.getVals(self) |
| + | local vals = {} |
| + | for _,v in pairs(self) do |
| + | table.insert(vals,v) |
| + | end |
| + | return vals |
| end | | end |
| | | |
Line 20: |
Line 38: |
| end | | end |
| | | |
− | function p.hashString(string) | + | function p.hashString(str) |
| local hash = 0 | | local hash = 0 |
− | for i = 1, #string do | + | if str == nil or str == "" then |
− | local letter = string:sub(i,i)
| + | return 0 |
− | hash = bit32.lshift(hash,3)
| + | end |
− | hash = hash+string.byte(letter) % (2^31-1)
| + | if type(str) == "string" and str ~= "" then |
| + | for i = 1, #str do |
| + | local letter = str:sub(i,i) |
| + | hash = bit32.lshift(hash,3) |
| + | hash = hash+str.byte(letter) % (2^31-1) |
| + | end |
| end | | end |
| return hash | | return hash |
| end | | end |
| | | |
| + | |
| + | -- Hashes a seed if given, if not just returns a hash based on current time. |
| function p.timeHash(seed) | | function p.timeHash(seed) |
| + | -- lmfao this function wasn't a hash at all because it would never |
| + | -- return the same thing twice. |
| + | math.randomseed(p.hashString("Amatsukaze-chan is best")) |
| + | |
| local randomizer = 0 | | local randomizer = 0 |
| | | |
Line 62: |
Line 91: |
| local time = os.time() | | local time = os.time() |
| local rand = math.random() | | local rand = math.random() |
− | local rtnHash = (math.floor(time*265314426625821*rand)-randomizer*time) % 2^32+math.floor(math.random()*1381242451)*randomizer | + | local rtnHash = (math.floor(time*5501*rand)-math.floor(randomizer*time) + math.floor(math.random()*5501*randomizer)) % 2^32 |
− | -- local step1 = math.floor(time*265314426625821*rand)
| + | return rtnHash |
− | -- local step2 = randomizer*time
| |
− | -- local step3 = step1-step2
| |
− | -- local step4 = step3 % 2^32
| |
− | -- local step5 = math.floor(math.random()*1381242451) | |
− | -- local step6 = step5*randomizer
| |
− | -- local step7 = step4 + step6
| |
− | -- local rtnStr = tostring(step1) .. " | " .. tostring(step2) .. " | " .. tostring(step3) .. " | " .. tostring(step4) .. " | " .. tostring(step5) .. " | " .. tostring(step6).. " | " .. tostring(step7) .. " | " .. tostring(rtnHash)
| |
− | local rtnStr = tostring(rtnHash)
| |
− | return rtnStr
| |
− | -- return (math.floor(time*265314426625821*rand)-randomizer) % 2^32+math.floor(math.random()*1381242451)
| |
| end | | end |
| | | |