| 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 rtnStr = tostring(time) .. " | " .. tostring(rand) .. " | " .. tostring(p.dictConcat(seed)) .. " | " .. tostring(randomizer) | + | local rtnHash = (math.floor(time*5501*rand)-math.floor(randomizer*time) + math.floor(math.random()*5501*randomizer)) % 2^32 |
| − | return rtnStr
| + | return rtnHash |
| − | -- return (math.floor(time*265314426625821*rand)-randomizer) % 2^32+math.floor(math.random()*1381242451)
| |
| | end | | end |
| | | | |