power outage recovery using DS1307 Real Time Clock

OK, Some great help so far I have gotten this much running

/*
* Q(1-2) - (Q1) Memory Load  (Q2) RTC - Memory Read  
 
 */
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address
// Global Variables
int command = 0;       // This is the command char, in ascii form, sent from the serial port     
byte zero;
int  state   = 50;     // State machine variable
int  counter = 4;      // Master counter variable
int magnum1 = 99;      // dummy var
int magnum2 = 99;      //  dummy var

void setup() {
  Wire.begin();           // join i2c bus
  Serial.begin(57600); 
  zero=0x00;             // not sure what this is for
}

void loop() {
  if (Serial.available()) {      // Look for char in serial que and process if found
    command = Serial.read();

    if (command == 81 || command == 113) {      //If command = "Qq" RTC1307 Memory Functions
      delay(100);     
      if (Serial.available()) {
        command = Serial.read(); 
        if (command == 49) {                //If command = "1"  load data to RAM
          Wire.beginTransmission(DS1307_I2C_ADDRESS);   // 255 will be the init value and 0 will be considered 
          Wire.write(32);                   // Set the register pointer to before data location
          Wire.write(magnum1);              // Write magic number before storing data
          Wire.write(state);                // Store State variable
          Wire.write(counter >> 8);         // writes the high byte of counter
          Wire.write(counter & 0xFF);       // writes the low byte of counter
          Wire.write(magnum2);              // Write magic number after storing data
          Wire.endTransmission();

          Serial.println("Data Stored");
        }
        else if (command == 50) {      //If command = "2" Read data from RAM
          Serial.println("Begin Read");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(zero);   // not sure what this is for 
          Wire.endTransmission();

          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write(0x20);         // not sure what this is doing
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 32);  // Set pointer to the first byte of data

          magnum1 = (Wire.read());  //magic number written before data write
          state = (Wire.read());    // Read state data
          counter = (Wire.read() << 8) + Wire.read(); // Read first byte shift left read second byte
          magnum2 = (Wire.read());  // Read Magic number written after data write
          Serial.print(" Magic Number = ");
          Serial.println(magnum1);
          Serial.print(" State = ");
          Serial.println(state);
          Serial.print(" Counter = ");
          Serial.println(counter);
          Serial.print(" Magic Number = ");
          Serial.println(magnum2);
          Serial.println(" RTC1307 Dump end");
        } 
      }  
    }
  }
  command = 0;                 // reset command 
  delay(100);
}
//********************************

now to figure out how to generate a random magic number