Software /
code /
prosody
Comparison
util/random.lua @ 6421:c3011ab945b8
util.random: Ensure at least 4 bytes of previous random state is used when generating new randomness
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Sep 2014 10:21:38 +0200 |
parent | 6420:0c070e30a7db |
child | 7050:ae044691de0f |
comparison
equal
deleted
inserted
replaced
6420:0c070e30a7db | 6421:c3011ab945b8 |
---|---|
29 local function seed(x) | 29 local function seed(x) |
30 buffer = new_random(buffer..x); | 30 buffer = new_random(buffer..x); |
31 end | 31 end |
32 | 32 |
33 local function bytes(n) | 33 local function bytes(n) |
34 if #buffer < n then seed(uniq_time()); end | 34 if #buffer < n+4 then seed(uniq_time()); end |
35 local r = buffer:sub(0, n); | 35 local r = buffer:sub(1, n); |
36 buffer = buffer:sub(n+1); | 36 buffer = buffer:sub(n+1); |
37 return r; | 37 return r; |
38 end | 38 end |
39 | 39 |
40 return { | 40 return { |