vlc.misc.mdate

Discuss your Lua playlist, album art and interface scripts.
ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

vlc.misc.mdate

Postby ale5000 » 04 Jul 2018 16:31

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?

mederi
Big Cone-huna
Big Cone-huna
Posts: 1949
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: vlc.misc.mdate

Postby mederi » 04 Jul 2018 19:10

Misc (Interfaces only)
----------------------
----------------------------------------------------------------
/!\ NB: this namespace is ONLY usable for interfaces.
Lua's os.date(), os.time(), os.clock()?

ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

Re: vlc.misc.mdate

Postby ale5000 » 05 Jul 2018 04:11

Thanks for the reply but the problem is that I no longer get microseconds :(

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37519
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: vlc.misc.mdate

Postby Jean-Baptiste Kempf » 05 Jul 2018 09:53

Why do you need that?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

Re: vlc.misc.mdate

Postby ale5000 » 05 Jul 2018 10:44

To feed math.randomseed(), seconds have too much chance to collide from different near calls.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37519
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: vlc.misc.mdate

Postby Jean-Baptiste Kempf » 05 Jul 2018 11:14

I don't think this is a good idea, tbh.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

Re: vlc.misc.mdate

Postby ale5000 » 05 Jul 2018 11:18

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?

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37519
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: vlc.misc.mdate

Postby Jean-Baptiste Kempf » 05 Jul 2018 19:21

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...
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

Re: vlc.misc.mdate

Postby ale5000 » 11 Jul 2018 16:57

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

ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

Re: vlc.misc.mdate

Postby ale5000 » 13 Jul 2018 16:49

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)) )
?

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37519
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: vlc.misc.mdate

Postby Jean-Baptiste Kempf » 15 Jul 2018 13:47

Sorry, but no.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 6 guests