aboutsummaryrefslogtreecommitdiffstats
path: root/util/uuid.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-06-04 19:55:56 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-06-04 19:55:56 +0500
commite60635aa94b327010fdd22ce32b162b420cfc4f4 (patch)
treecc27980462a17c737f23238e1871eb186a4ce23a /util/uuid.lua
parent4ee16e78eb4e74bd20062a19c331d70c87323712 (diff)
downloadprosody-e60635aa94b327010fdd22ce32b162b420cfc4f4.tar.gz
prosody-e60635aa94b327010fdd22ce32b162b420cfc4f4.zip
util.uuid: Added function seed(string) to allow further seeding of the PRNG
Diffstat (limited to 'util/uuid.lua')
-rw-r--r--util/uuid.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/util/uuid.lua b/util/uuid.lua
index a6dc0a1e..eca35134 100644
--- a/util/uuid.lua
+++ b/util/uuid.lua
@@ -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;