Problem reading random noise generator

Hey there! Sorry it has taken me a while to reply; due to some unavoidable personal stuff I had to wait until tonight to work on this.

My median and standard deviation are 56 and 15, respectively, with an analog reading sample size of 500,000 samples.

Here are my oscilloscope results. I am using the same circuit as I posted before, but with no filtering for any sort of Nyquist frequency.
This capture was taken at the output, with the values given. The waveform is grouping itself, it seems, on the lower end (around 100 mV), so I thought that this could explain the grouping of my samples on the lower end of the scale. After some fiddling and calculating, I replaced the high resistor on the divider with a 6.8k ohm resistor, and the lower one with a 20k ohm resistor, and got this noise waveform. It seems to me that this is far more evenly distributed, as well as with a higher amplitude. The charts in the attached Excel sheet have been created using this circuit. Interestingly, it has not changed my median. Also, my median is rather constant, and rather low - always now between 40 and 50. This is true of both the initial circuit and the new one.
Then I changed the AnalogRef pin as you suggested, with a reference of 3V, as the maximum noise looked to be about 2.9 volts.
This changes the median to ~75.

When I run the code through whitening algorithms, the distribution looks pretty good, however, and this I feel is the real final challenge, the mapping is still horrendous. As you can see by the charts in the attached spreadsheet, the "mapped" distributions are all over the place. Why might this be?

Here is my new code:

/********************************/
/*  Rob Seward 2008-2009        */
/*  v1.0                        */
/*  4/20/2009                   */
/********************************/

#define BINS_SIZE 256
#define CALIBRATE_SIZE 10000

#define NO_BIAS_REMOVAL 0
#define EXCLUSIVE_OR 1
#define VON_NEUMANN 2

#define ASCII_BYTE 0
#define BINARY 1
#define ASCII_BOOL 2

#define LED_PIN 13
#define ADC_PIN A0

/***  Configure the RNG **************/
int bias_removal = VON_NEUMANN;
int output_format = ASCII_BOOL;
int baud_rate = 19200;
/*************************************/


unsigned int Bins[BINS_SIZE];
unsigned int Results[20];
boolean initializing = true;
unsigned int calibration_counter = 0;

boolean bufferFull = false;
byte buffer = 0;
byte threshold = 0;

unsigned long samples = 0;
unsigned long maxSamples = 170588;

void setup(){
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(baud_rate);
  for (int i=0; i < BINS_SIZE; i++){
    Bins[i] = 0; 
  }  
}

void loop(){

  Serial.println("Initializing...");
  Serial.println("Calibrating...");
  threshold = calibrate();
  Serial.print("Threshold: ");Serial.println(threshold);
  delay(2000);
  Serial.println("Collecting Data");
  for (int i=0; i < BINS_SIZE; i++){
    Bins[i] = 0; 
  }  
  while(samples < maxSamples)
  {
    //byte rand = getRandomByte(threshold);
    //Bins[rand]++;
    uint32_t rand = map20();
    Results[rand]++;
    Serial.print(samples);Serial.print(": ");Serial.println(rand);
    samples++;
  }
  
  Serial.println("Distribution:");
  for (int i=0; i < BINS_SIZE; i++){
    Serial.print(i);Serial.print(": ");Serial.println(Bins[i]);
  }  
  for (int i=0; i < 20; i++){
    Serial.print(i);Serial.print(": ");Serial.println(Results[i]);
  } 
  while(true){}
}

byte getRandomByte(byte tHold)
{
  while(!bufferFull)
  {
    int adc_value = analogRead(ADC_PIN);
    byte adc_byte = adc_value >> 2;
    processInput(adc_byte, tHold);
  }
  bufferFull = false;
  return buffer;
}

void processInput(byte adc_byte, byte threshold){
  boolean input_bool;
  input_bool = (adc_byte < threshold) ? 1 : 0;
  switch(bias_removal){
    case VON_NEUMANN:
      vonNeumann(input_bool); 
      break;
    case EXCLUSIVE_OR:
      exclusiveOr(input_bool);
      break;
    case NO_BIAS_REMOVAL:
      buildByte(input_bool);
      break;
  }
}

void exclusiveOr(byte input){
  static boolean flip_flop = 0;
  flip_flop = !flip_flop;
  buildByte(flip_flop ^ input);
}

void vonNeumann(byte input){
  static int count = 1;
  static boolean previous = 0;
  static boolean flip_flop = 0;
  
  flip_flop = !flip_flop;

  if(flip_flop){
    if(input == 1 && previous == 0){
      buildByte(0);
    }
    else if (input == 0 && previous == 1){
      buildByte(1); 
    }
  }
  previous = input;
}

void buildByte(boolean input){
  static int byte_counter = 0;
  static byte out = 0;

  if (input == 1){
    out = (out << 1) | 0x01;
  }
  else{
    out = (out << 1); 
  }
  byte_counter++;
  byte_counter %= 8;
  if(byte_counter == 0){
    if (output_format == ASCII_BYTE) Serial.println(out, DEC);
    buffer = out;
    bufferFull = true;
    out = 0; 
    return;
  }
  bufferFull = false;
}



unsigned int calibrate()
{
  digitalWrite(LED_PIN,HIGH);
  for(int i = 0; i < CALIBRATE_SIZE; i++)
  {
    int adc_value = analogRead(ADC_PIN);
    byte analog = adc_value >>2;//truncates to 0-255
    Bins[analog]++;
  }
  
  //find the median
  unsigned long half;
  unsigned long total = 0;
  int i;

  for(i=0; i < 256; i++){
    total += Bins[i];
  }	

  half = total >> 1;
  total = 0;
  for(i=0; i < 256; i++){
    total += Bins[i];
    if(total > half){
      break;
    }	
  }
  digitalWrite(LED_PIN,LOW);
  return i;
}

uint32_t map20()
{
  uint32_t slice;
  uint32_t retVal = 0xFFFFFFFF;

  slice = 0xFF / 20;
  while (retVal >= 20)
  {
    byte r = getRandomByte(threshold);
    retVal = r / slice;
    Bins[r]++;
  }
  
  return(retVal);
}

Stats2.xlsx (39.9 KB)