Scramble Output During Setup Function Help

Hey there,

I'm trying to code something that changes a certain output, after a certain input is sensed. Please see the tables below for a better explanation.

| If 5V input Sensed on: | Then Output 5v on: | | - | - | | A1 | D1 | | A2 | D2 | | A3 | D3 | | A4 | D4 |

Now, if I hit reset, I want my program to randomize the output for an input within an array of say [D1,D2,D3,D4,D5,D6] without using an output more than once.

| If 5V input Sensed on: | Then Output 5v on: | | - | - | | A1 | D4 | | A2 | D6 | | A3 | D1 | | A4 | D2 |

I know I need to make all of this happen during the setup() function and in python I'm sure I'd used a dictionary to setup the key:value pair of input:output. Are there analogous data types to python dictionary in c++ that I could use to help solve this problem?

Thanks for the help.

Just use several arrays. You might need to save the current state in EEPROM, so that you can randomize it on startup.

you need to define an output array (pin numbers) and during setup you swap random elements 100 times

int pincount = 4;
int outputPins[] = { 3, 4, 5, 6 };

void setup()
{
  // pinMode..
  Serial.begin(9600);
  
  while(Serial.available() == 0); // wait until keypress
  randomSeed( micros() );

  // swap pins randomly
  for (int i=0; i<pincount; i++)
  {
     int a = random(pincount);
     int temp = outputPins[i];
     outputPins[i] = outputPins[a];
     outputPins[a] = temp;
   }

   // print to check
   for (int i=0; i<pincount; i++)
  {
     Serial.println( outputPins[i] );
   }  
}
void loop(){}

(no need to store previous

We don't know that he has a key to press...

just a proof of concept snippet …