Software /
code /
prosody
Diff
util/random.lua @ 6423:1c78f10f05d0
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 23 Sep 2014 01:44:16 +0200 |
parent | 6421:c3011ab945b8 |
child | 7050:ae044691de0f |
line wrap: on
line diff
--- a/util/random.lua Tue Sep 16 17:11:29 2014 -0400 +++ b/util/random.lua Tue Sep 23 01:44:16 2014 +0200 @@ -10,7 +10,7 @@ local os_time = os.time; local os_clock = os.clock; local ceil = math.ceil; -local sha1 = require "util.hashes".sha1; +local H = require "util.hashes".sha512; local last_uniq_time = 0; local function uniq_time() @@ -21,7 +21,7 @@ end local function new_random(x) - return sha1(x..os_clock()..tostring({})); + return H(x..os_clock()..tostring({})); end local buffer = new_random(uniq_time()); @@ -31,8 +31,8 @@ end local function bytes(n) - if #buffer < n then seed(uniq_time()); end - local r = buffer:sub(0, n); + if #buffer < n+4 then seed(uniq_time()); end + local r = buffer:sub(1, n); buffer = buffer:sub(n+1); return r; end