Randomly pick one variable

Of course it is. I’m not sure I understood what you meant. There are shorter ways to do this, but less readable and understandable

int ran;
if(a == -1 && b == 1) {  //check if a = -1 and b = 1
  if(random(2) < 1) { //Generate random number between 0 and 2. If < 1 set ran=a,
    ran = a;
  } else { //else random(2) is >= 1. set ran=b
    ran = b;
}
3 Likes