Skip to content

Commit

Permalink
fix(randomseed) do not randomseed from a library
Browse files Browse the repository at this point in the history
The rnadom number generator contains application level state
and hence should NEVER be seeded from a library. Seeding it is
an application level responsibility, always.
  • Loading branch information
Tieske committed Oct 26, 2021
1 parent ab2872a commit e3fa62c
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions mqtt/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ local coroutine_yield = coroutine.yield

local math = require("math")
local math_random = math.random
local math_randomseed = math.randomseed

local luamqtt_VERSION

Expand All @@ -55,11 +54,6 @@ local ioloop_get = ioloop.get

-------

-- pseudo-random generator initialized flag
local random_initialized = false

-------

--- MQTT client instance metatable
-- @type client_mt
local client_mt = {}
Expand Down Expand Up @@ -158,11 +152,6 @@ function client_mt:__init(args)

if not a.id then
-- generate random client id
if not random_initialized then
-- initialize pseudo-random generator with current time seed
math_randomseed(os_time())
random_initialized = true
end
a.id = str_format("luamqtt-v%s-%07x", str_gsub(luamqtt_VERSION, "[^%d]", "-"), math_random(1, 0xFFFFFFF))
end

Expand Down

0 comments on commit e3fa62c

Please sign in to comment.