1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-16 20:59:48 +00:00

commit new z.lua

This commit is contained in:
skywind3000
2018-04-02 23:05:36 +08:00
parent 41e0f7ac6b
commit ea0b889995

7
z.lua
View File

@@ -429,13 +429,18 @@ end
-- initialize random seed
-----------------------------------------------------------------------
function math.random_init()
-- init random seed
-- random seed from os.time()
local seed = tostring(os.time()):reverse()
for _, key in ipairs(os.argv) do
seed = seed .. '/' .. key
end
local ppid = os.getenv('PPID')
seed = (ppid ~= nil) and (seed .. '/' .. ppid) or seed
-- random seed from socket.gettime()
local status, socket = pcall(require, 'socket')
if status then
seed = seed .. tostring(socket.gettime())
end
local number = 0
for i = 1, seed:len() do
local k = string.byte(seed:sub(i, i))