Hlp me out with a simple question

I wrote a simple program with goal of making an LED display at a random brightness each second. The problem is that the LED is always either on or off the brightness doesn't change. What am I missing?

int ledPin = 13;           // LED connected to digital pin 13
int val = 0;                      // hold a random value

void setup() {                      // run once, when the sketch starts
  pinMode( ledPin, OUTPUT );  // sets the digital pin as output
}

void loop() {                      // run over and over again
  val = random( 256 );          // Generate a random number
  analogWrite( ledPin, val );    // sets the LED brightness to random value
  delay( 1000 );                        // waits for a second
}

Never mind, I just realized I was using PIN 13 which doesn't support PWM. Switched to PIN 9 and everything is working.