In a LUA sd script I was using vlc.misc.mdate and it was working in VLC 1.1.0 (about) but now it no longer work.
Is there a replacement?
Lua's os.date(), os.time(), os.clock()?Misc (Interfaces only)
----------------------
----------------------------------------------------------------
/!\ NB: this namespace is ONLY usable for interfaces.
If on 2 PC in the entire world 2 users use the same script in the same second then the random values will collide.
The chance are low if the users are few but more users more chance to collide.
Is there an alternative to get a safer random value?
Code: Select all
local rand_table, real_rand
function get_rand()
local ret
local table_size = 99
if rand_table == nil then
local seed
rand_table = {}
real_rand = math.random
if vlc ~= nil and vlc.misc ~= nil then seed = vlc.misc.mdate() else seed = os.time() end
math.randomseed(tonumber(tostring(seed):reverse():sub(1, 6)))
real_rand()
for i = 1, table_size do
rand_table[i] = real_rand()
end
end
local i = 1 + math.floor(real_rand() * (table_size))
ret, rand_table[i] = rand_table[i], real_rand()
return ret
end
function get_rand_minmax(min, max)
if min > max then error("bad argument #1 to 'get_rand_minmax' (interval is empty)") end
return min + math.floor(get_rand() * (max-min+1))
end
Regarding this change: https://github.com/videolan/vlc/commit/ ... f8aa5b3915vlc_rand is not exported...
Code: Select all
min + ( math.floor(rand_functions() * (max-min+1)) )
Return to “Scripting VLC in lua”
Users browsing this forum: No registered users and 4 guests