Page 1 of 1

Add a random value to a script. Need some help

Posted: 22 Jun 2017 18:34
by Nikk_
Hello all,

I've been looking for a way to play a files in a playlist in a true random manner - files playing random, from a random starting point and for a random duration.
While there were few other posts on the internet about this same thing, I couldn't find an answer and a way to do this. The closest thing to the above is this addon called Sampler: https://addons.videolan.org/content/sho ... ent=149688
It does a fine job but the problem is that it doesn't play the file for a random duration. It rather plays the files for a predetermined duration.
I googled "random generated number in lua" and tried messing with the lua script to add a line for it but I simply don't know anything about lua and couldn't do anything.

So the Sampler cuts the video onto pieces (samples per item field) and I want each sample to have a random duration (lets say between 10 and 600 seconds, or until it ends) determined by this RNG.
Is this even possible in lua (vlc)? Could anybody help me out and point me a way to do this? Even if it's external program/script or another player. I'm willing to try anything at this point :)

Thank you.

Re: Add a random value to a script. Need some help

Posted: 23 Jun 2017 00:09
by Etoh
For random numbers I think you can use math.randomseed(os.time()) and math.random(range).

Re: Add a random value to a script. Need some help

Posted: 23 Jun 2017 09:14
by Nikk_
Yeah, that's what I found out from google too, but couldn't make the lua work after inserting it here and there. It just broke. :(
Like I said my understanding of lua is virtually non existent...

Re: Add a random value to a script. Need some help

Posted: 23 Jun 2017 14:44
by mederi
I want each sample to have a random duration (lets say between 10 and 600 seconds, or until it ends)
You can edit "Sampler (PG).lua" script, line 166:

Code: Select all

"stop-time="..(sample_position+sample_duration) "stop-time="..(sample_position+math.random(10, 600))

Re: Add a random value to a script. Need some help

Posted: 23 Jun 2017 17:17
by Nikk_
Amazing !!! Works like a charm.

Btw, how does the scrip "decide" where the sample will begin? It kind of seems random to me. I tried replacing "start-time="..sample_position with math.random(..) but couldn't determine if that did anything or not. It didn't break the script though, which is a good thing :D
Is there any way to make the above and the number of samples as a random range as well? Just make it fully random :)

Anyway huge thank you for the help and for the script you wrote Mederi.
Top notch work!