aboutsummaryrefslogtreecommitdiffstats
path: root/util/random.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/random.lua')
-rw-r--r--util/random.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/util/random.lua b/util/random.lua
new file mode 100644
index 00000000..4963e98c
--- /dev/null
+++ b/util/random.lua
@@ -0,0 +1,23 @@
+-- Prosody IM
+-- Copyright (C) 2008-2014 Matthew Wild
+-- Copyright (C) 2008-2014 Waqas Hussain
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+local urandom = assert(io.open("/dev/urandom", "r+"));
+
+local function seed(x)
+ urandom:write(x);
+ urandom:flush();
+end
+
+local function bytes(n)
+ return urandom:read(n);
+end
+
+return {
+ seed = seed;
+ bytes = bytes;
+};