mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 05:37:39 +03:00
util.uuid: Added function seed(string) to allow further seeding of the PRNG
This commit is contained in:
parent
4ee16e78eb
commit
e60635aa94
1 changed files with 5 additions and 3 deletions
|
@ -28,10 +28,11 @@ local function new_random(x)
|
|||
end
|
||||
|
||||
local buffer = new_random(uniq_time());
|
||||
local function _seed(x)
|
||||
buffer = new_random(buffer..x);
|
||||
end
|
||||
local function get_nibbles(n)
|
||||
if #buffer < n then
|
||||
buffer = new_random(buffer..uniq_time());
|
||||
end
|
||||
if #buffer < n then seed(uniq_time()); end
|
||||
local r = buffer:sub(0, n);
|
||||
buffer = buffer:sub(n+1);
|
||||
return r;
|
||||
|
@ -44,5 +45,6 @@ function generate()
|
|||
-- generate RFC 4122 complaint UUIDs (version 4 - random)
|
||||
return get_nibbles(8).."-"..get_nibbles(4).."-4"..get_nibbles(3).."-"..(get_twobits())..get_nibbles(3).."-"..get_nibbles(12);
|
||||
end
|
||||
seed = _seed;
|
||||
|
||||
return _M;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue