Line 1: |
Line 1: |
| local p = {} | | local p = {} |
| + | |
| + | local bit32 = require( 'bit32' ) |
| + | |
| -- Module for random library functions for lua because lua sucks. Written by | | -- Module for random library functions for lua because lua sucks. Written by |
| -- Remi_Scarlet | | -- Remi_Scarlet |
| -- I fucking hate lua. | | -- I fucking hate lua. |
| + | |
| | | |
| | | |
Line 10: |
Line 14: |
| end | | end |
| | | |
− | function p.timeHash() | + | function p.hashString(string) |
| + | local hash = 0 |
| + | for letter in string do |
| + | hash = bit32.lshift(hash,1) |
| + | hash = hash+string.byte(letter) % (2^31-1) |
| + | end |
| + | end |
| + | |
| + | function p.timeHash(seed) |
| + | local randomizer = 0 |
| + | if type(seed) == "table" then |
| + | for k,v in pairs(dict) do |
| + | randomizer = randomizer + p.hashString(k) |
| + | if type(v) == "string" then |
| + | randomizer = randomizer + p.hashString(v) |
| + | end |
| + | if type(v) == "number" then |
| + | randomizer = randomizer + v |
| + | end |
| + | end |
| + | end |
| + | if type(seed) == "string" then |
| + | randomizer = p.hashString(seed) |
| + | end |
| + | if type(seed) == "number" then |
| + | randomizer = seed |
| + | end |
| local time = os.time() | | local time = os.time() |
| local rand = math.random(-1,1) | | local rand = math.random(-1,1) |
− | return math.floor(time*265314426625821*rand) % 2^32+math.floor(math.random(-1,1)*1381242451) | + | return (math.floor(time*265314426625821*rand*randomizer)-randomizer) % 2^32+math.floor(math.random(-1,1)*1381242451) |
| end | | end |
| | | |