util/random.lua

Mon, 04 Jan 2016 17:03:19 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 04 Jan 2016 17:03:19 +0000
changeset 18
8050134f35b3
parent 9
7da8b3c95bb1
permissions
-rw-r--r--

clients: Include request in the new-client event

9
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Prosody IM
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2014 Matthew Wild
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2014 Waqas Hussain
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local urandom = assert(io.open("/dev/urandom", "r+"));
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function seed(x)
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 urandom:write(x);
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local function bytes(n)
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 return urandom:read(n);
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 return {
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 seed = seed;
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 bytes = bytes;
7da8b3c95bb1 Add and remove missing/deleted files
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 };

mercurial