Page 1 of 1

generate random number

PostPosted: Tue Jan 09, 2024 5:07 pm
by videodsh
Hey guys,

maybe one of you creative programmers has an idea how to solve this:

i need widgetdesgner to switch my ATEM PGM BUS every 5 seconds to another source. (between Inputs 1-5)
My idea was to create a generator node wich wil generate random numbers between 1 and 5 an a script timer to execute the ATEM switching.

Switching works fine, but what happens is that the random number sometimes is the same as the previous one. so in fact there is no switching.
You understand, what I mean?

so I need to find a way to generate a number between 1 and 5 wich MUST be different from previous number.


In a second step i need to exclude one or more numbers, lets say just switch between Cam 3,4 and 5, or 1,3,4 etc.

I would like to have 5 toggle Buttons named Cam 1 to Cam 5 and press them in order to be part of the random thing.

Maybe anyone has an idea.

thanks in advance

cheers

Re: generate random number

PostPosted: Wed Jan 10, 2024 7:56 am
by satanete666
i think the easyest way is to do is to store the last value in a global variable and in you re script timer do a if else sentece where you can see if the new number is the same that you have store in the variable then you can substract or add value to this number to be different.

Regards

Re: generate random number

PostPosted: Wed Jan 10, 2024 2:07 pm
by videodsh
var_mix = Math.Random(1,6)

Label1.text = var_mix

if var_mix = var_lastnumber {
WDCustomScriptClick(5)

Good advice, my workaround is now a customscript button
the on Click script puts the last value into var_lastnumber
the on release script generates a number, compares it to the var_lastnumber and repeats if both values are the same.

working , half way done, but now comes the tricky part

math.random generates a random number within the boundaries (min,max)
but I need to choose a number of a pre-defined list i.e. 1,2,5 or 2,3,4,5

Any Idea on that

Re: generate random number

PostPosted: Thu Jan 11, 2024 2:37 am
by Daniel Kaminski
Nice Challange.

I would create an Array that holds all the ID of the Cameras you can Switch.
Than you only need to remove the currently switched Camera from the Array and generate a random Number over the amount of elements of the array.

I created a small example how I would do it.

Feel free to use it and feedback and questions are welcome.

Daniel