Arduino timer disaster

I've been working on a project that has an led and a pin in the breadboard. Basically, Im trying to get the led to turn on at random then press a button to turn it off and the timer is suppose to measure the amount of time it takes from when the led turns on till you press the button and turn it off. I'm new to arduino and I have bits and pieces of what I think the code should be, but have no idea how to put it all together. Help? Please?

int led = 13;
int butt = 2;
int buttstate = 0;
long randOn = 0;                  // Initialize a variable for the ON time
long randOff = 0;                 // Initialize a variable for the OFF time
unsigned long time;

void setup() {
  // initialize the LED pin as an output:
  pinMode(led, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(butt, INPUT);
  Serial.begin(9600);  
}

void loop()                       // run over and over again
{

  buttstate = digitalRead(butt);
if (buttstate == HIGH) {     
    // turn LED on:    
    digitalWrite(led, LOW);
  
  randOn = random (1000, 10000);    // generate ON time between 0.1 and 1.2 seconds
  randOff = random (1000, 5000);    // generate OFF time between 0.2 and 0.9 seconds
    digitalWrite(led, HIGH);   // sets the LED on
    delay(randOn);                // waits for a random time while ON
    digitalWrite(led, LOW);    // sets the LED off
    delay(randOff);               // waits for a random time while OFF


while ( digitalRead(led, HIGH)
{Serial.print("Time: ");
  time = millis();
  //prints time since program started
  Serial.println(time);
}}

Your sketch won't format (Tools -> Auto Format) because "Too many left parentheses." Fixing that leads to "Too many left curly braces." Try something like this:

const byte ledPin = 13;
boolean ledOn;
const byte buttPin = 2;

unsigned long randOnStart;
unsigned long randOnInterval;                  // Initialize a variable for the ON time
unsigned long reactionTimeStart;

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);   
  digitalWrite(ledPin, LOW);
  ledOn = false;

  // initialize the pushbutton pin as an input:
  pinMode(buttPin, INPUT);
  Serial.begin(9600);
  randOnInterval = random (1000, 10000);    // generate ON time between 1 and 10 seconds
  randOnStart = millis();

}

void loop() {
  if (ledOn) {
    // LED is on so check the button
    if (digitalRead(buttPin)) {     
      // LED on and Button pressed so turn the LED off   
      digitalWrite(ledPin, LOW);
      ledOn = false;
      // Display the time between LED On and LED Off
      unsigned long reactionTime = millis() - reactionTimeStart;
      Serial.print("Reaction time: ");
        Serial.println(reactionTime);
      // Start another cycle
      randOnInterval = random (1000, 10000);    // generate ON time between 1 and 10 seconds
      randOnStart = millis();
    }
  }
  else {// LED is off
    // Did someone press the button early?
    if (millis() - randOnStart > 500) { // Allow half a second
      Serial.println("You pressed too early!");
      // Re-start the LED On timer
      randOnStart = millis();
    }

    // Is it time to turn the LED on?
    if (millis() - randOnStart > randOnInterval) {
      digitalWrite(ledPin, HIGH);
      ledOn = true;
      reactionTimeStart = millis();
    }
  }
}
unsigned long time;

What time? What is that variable supposed to represent? When the LED was turned on? When the switch was pressed? Meaningful names will go a long ways towards making your program understandable - to us AND to you.

johnwasser gave you a good example of code that will do what you probably desire. I thought it would be helpful to show you the major discrepancies between what you described and what your original code is actually doing.

What you’re describing is:

  1) Pause for a random length of time.
  2) Turn on LED.
  3) Begin timer.
  4) Wait for button to be pressed.
  5) Stop timer.
  6) Turn off LED.
  7) Back to top of loop().

What your code actually does:

  1) If button is currently pressed then turn off the LED. (Doesn't really matter, 
     because there is no case for the LED to ever be on at this point.)
  2) Turn on the LED.
  3) Delay between 1 and 10 seconds.
  4) Turn off the LED.
  5) Delay between 1 and 5 seconds.
  6) Read the state of pin "led". (It will always be LOW, which is good, 
     because the existing "while" statement will loop infinitely.)
  7) Back to top of loop().

Ignoring the other issues, your original “while” statement presents some real problems.
First,
  while ( digitalRead(led, HIGH)should be

  while (digitalRead(led) == HIGH)

The bigger problem: A “while” statement is a conditional loop, and nothing within yours allows for the led pin to change state.

while (digitalRead(led) == HIGH)
{
  Serial.print("Time: ");
  time = millis();
  //prints time since program started
  Serial.println(time);
}

If this “while” statement were to evaluate true, it would enter an infinite loop.