Page 1 of 1

vlc.misc.mdate

Posted: 04 Jul 2018 16:31
by ale5000
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?

Re: vlc.misc.mdate

Posted: 04 Jul 2018 19:10
by mederi
Misc (Interfaces only)
----------------------
----------------------------------------------------------------
/!\ NB: this namespace is ONLY usable for interfaces.
Lua's os.date(), os.time(), os.clock()?

Re: vlc.misc.mdate

Posted: 05 Jul 2018 04:11
by ale5000
Thanks for the reply but the problem is that I no longer get microseconds :(

Re: vlc.misc.mdate

Posted: 05 Jul 2018 09:53
by Jean-Baptiste Kempf
Why do you need that?

Re: vlc.misc.mdate

Posted: 05 Jul 2018 10:44
by ale5000
To feed math.randomseed(), seconds have too much chance to collide from different near calls.

Re: vlc.misc.mdate

Posted: 05 Jul 2018 11:14
by Jean-Baptiste Kempf
I don't think this is a good idea, tbh.

Re: vlc.misc.mdate

Posted: 05 Jul 2018 11:18
by ale5000
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?

Re: vlc.misc.mdate

Posted: 05 Jul 2018 19:21
by Jean-Baptiste Kempf
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?

vlc_rand is not exported...

Re: vlc.misc.mdate

Posted: 11 Jul 2018 16:57
by ale5000
I have created a function to get a random number (with auto-seed on the first run), it should work-around bugs under all platforms.
It isn't perfectly safe but I think it is the most safe that I can get (it works also under plain LUA).

It is here:

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

Re: vlc.misc.mdate

Posted: 13 Jul 2018 16:49
by ale5000
vlc_rand is not exported...
Regarding this change: https://github.com/videolan/vlc/commit/ ... f8aa5b3915

Can please be added a function that return a decimal number between 0 and 1 (1 itself not included) so it match the behaviour of original lua function and also in this way min / max can be easily set with:

Code: Select all

min + ( math.floor(rand_functions() * (max-min+1)) )
?

Re: vlc.misc.mdate

Posted: 15 Jul 2018 13:47
by Jean-Baptiste Kempf
Sorry, but no.