Analog read signals sometimes reversing? (RESOLVED)

I have a project that analyzes data from two analog pins and records the values at 2-second intervals. However, during testing, the values occasionally swap. The sensors are being fed constant input and I get something that looks like this (each line is a new reading):

Babs: 547 Meter: 380 Babs: 547 Meter: 380 Babs: 547 Meter: 381 Babs: 547 Meter: 380 Babs: 380 Meter: 547 Babs: 380 Meter: 547 Babs: 379 Meter: 547 Babs: 547 Meter: 380 Babs: 547 Meter: 380

Any ideas what could be causing this?

That could be caused by a bug in your sketch. If you post your sketch, perhaps someone will spot an error.

Any ideas what could be causing this?

Maybe some type of sequencing weakness in your code.

There are actually several sketches running on several Arduino boards simultaneously. The master code is beyond the scope of my question, but what it does is wait for an external signal (provided every two seconds) and then ask other Arduinos to perform analog reads of the various sensors that are hooked up to them. Here’s the sketch for the data that occasionally flips:

#include <Wire.h>
#define meter 0
#define bsca  1
#define laser 9

int data;
byte datapacket[2];
const int avg = 20;
int bscadata[avg];
int meterdata[avg];
int freq = 200;

boolean toggle = true;

void setup()
{
  Wire.begin(2);                // address #2
  Wire.onRequest(requestEvent);
  //analogReference(EXTERNAL);
  pinMode(laser, OUTPUT);
  pinMode(meter, INPUT);
  pinMode(bsca, INPUT);
  Serial.begin(9600);
  tone(laser, freq);

}

void loop()
{
  // haha empty loop
}

void requestEvent()
{
  int bscaavg = 0;
  int meteravg = 0;
  
  for(int i=0; i<avg; i++) // do a collection
  {
    bscadata[i] = analogRead(bsca);
    meterdata[i] = analogRead(meter);
  }
    
  if(toggle)
  {
    for(int i = 0; i<avg; i++)
    {
      bscaavg = bscaavg + bscadata[i];
    }
    bscaavg = bscaavg/avg;
    pack(bscaavg);
    outgoing();
    toggle = !toggle;
  }
  else
  {
   for(int i = 0; i<avg; i++)
    {
      meteravg = meteravg + meterdata[i];
    }
    meteravg = meteravg/avg;
    pack(meteravg);
    outgoing();
    toggle = !toggle;
  }
}

void outgoing()
{
  Wire.send(datapacket,2);
}

void pack(int n)
{
  datapacket[0]=(byte)(n>>8);
  datapacket[1]=(byte)(n);
}

I figured out the problem.

In the master code, it was calling for 2 sets of data from one board without any sort of delay between the calls. This probably led to some lags in reporting, and the data got switched around.