Software /
code /
prosody
Comparison
util/random.lua @ 6420:0c070e30a7db
util.random: Switch to SHA512
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Sep 2014 10:16:59 +0200 |
parent | 6376:bd812a7713ad |
child | 6421:c3011ab945b8 |
comparison
equal
deleted
inserted
replaced
6417:060b63a27e9b | 6420:0c070e30a7db |
---|---|
8 | 8 |
9 local tostring = tostring; | 9 local tostring = tostring; |
10 local os_time = os.time; | 10 local os_time = os.time; |
11 local os_clock = os.clock; | 11 local os_clock = os.clock; |
12 local ceil = math.ceil; | 12 local ceil = math.ceil; |
13 local sha1 = require "util.hashes".sha1; | 13 local H = require "util.hashes".sha512; |
14 | 14 |
15 local last_uniq_time = 0; | 15 local last_uniq_time = 0; |
16 local function uniq_time() | 16 local function uniq_time() |
17 local new_uniq_time = os_time(); | 17 local new_uniq_time = os_time(); |
18 if last_uniq_time >= new_uniq_time then new_uniq_time = last_uniq_time + 1; end | 18 if last_uniq_time >= new_uniq_time then new_uniq_time = last_uniq_time + 1; end |
19 last_uniq_time = new_uniq_time; | 19 last_uniq_time = new_uniq_time; |
20 return new_uniq_time; | 20 return new_uniq_time; |
21 end | 21 end |
22 | 22 |
23 local function new_random(x) | 23 local function new_random(x) |
24 return sha1(x..os_clock()..tostring({})); | 24 return H(x..os_clock()..tostring({})); |
25 end | 25 end |
26 | 26 |
27 local buffer = new_random(uniq_time()); | 27 local buffer = new_random(uniq_time()); |
28 | 28 |
29 local function seed(x) | 29 local function seed(x) |