Variable set to the value of one of two possible other variable values randomly

Hello! So in my game I am working on a monster breeding system just to add a little context to my example.

Parent A
color variable = 8

Parent B
color variable =4

Baby
color variable = either 8 or 4 randomly

I'm far enough that the parent variables are set to those numbers based on which monsters you want to breed now I just need to figure out how to set the babies color variable. So far this is what I have but it obviously doesn't work. I've only been working with rpg maker since march so I get the very basics but this is a little bit out of my grasp.
Spoiler: Incorrect Code
var vr1 = $game_variables[122]
var vr2 = $game_variables[130]
var arr = [vr1, vr2]; arr[Math.randomInt(arr.length)]
$gameVariables.setValue(137, arr);
I realize now this isnt in the correct spot and I don't know how to move it or delete it so I'm sorry.
Hi there!
The syntax for the first two variables is wrong. The right is:
$gameVariables.value(id)
And for the math random, you are calculating the arr.length wrong too. Since it's returning 2 because are two elements in the array.
But the array starts with 0.
So you have, in this case, arr[0] and arr[1] which means length = 2.
you have to put:
arr.length-1 inside math random.
See if it works.
Thanks for the quick reply! It's a step closer now my issue is the "baby" color variable equals both 6 and 8 while I want it to choose one or the other. Sorry I kind of need my hand held using script is super new for me.

Spoiler: Updated Code
var vr1 = $gameVariables.value(122)
var vr2 = $gameVariables.value(130)
var arr = [vr1, vr2]; arr[Math.randomInt(arr.length-1)]
$gameVariables.setValue(137, arr);
Hi there!
The syntax for the first two variables is wrong. The right is:
$gameVariables.value(id)
And for the math random, you are calculating the arr.length wrong too. Since it's returning 2 because are two elements in the array.
But the array starts with 0.
So you have, in this case, arr[0] and arr[1] which means length = 2.
you have to put:
arr.length-1 inside math random.
See if it works.
Hey sorry I'm learning using the forums too haha I didn't reply correctly. I followed your advice I think but now the baby color is set to 8 and 6 instead of one or another. I posted my updated scripts a few minutes ago.
And for the math random, you are calculating the arr.length wrong too. Since it's returning 2 because are two elements in the array.
But the array starts with 0.
So you have, in this case, arr[0] and arr[1] which means length = 2.
you have to put:
arr.length-1 inside math random.
See if it works.
This is incorrect, as Math.randomInt(n) returns a value in the range [0,n) - that is, 0 to n excluding n. So the original usage of Math.randomInt in the opening post was correct.

The real problem with the code is that the randomly-selected value was just thrown away. Try this instead for the second half of your code:

JavaScript:
var choose = [vr1, vr2][Math.randomInt(2)]
$gameVariables.setValue(137, choose);
This is incorrect, as Math.randomInt(n) returns a value in the range [0,n) - that is, 0 to n excluding n. So the original usage of Math.randomInt in the opening post was correct.

The real problem with the code is that the randomly-selected value was just thrown away. Try this instead for the second half of your code:

JavaScript:
var choose = [vr1, vr2][Math.randomInt(2)]
$gameVariables.setValue(137, choose);
You're amazing! I think I learned a little along the way and I hope this can help other people! Thank you sooooo much it works exactly as I hoped!

Original thread: https://forums.rpgmakerweb.com/threads/variable-set-to-the-value-of-one-of-two-possible-other-variable-values-randomly.122861/