The first two letters are the airline code, like CO for Continental. The flight schedulers have a list of ranges for different flight types (transcons, international, point-to-point, ferry flights, overnight, extra section, commuter, regional, etc.), they are then assigned in order of departure, and then they normally choose even numbers for eastbound, and odds for westbound. Sometimes (especially for regionals) the flight number will be the same going to and from a city. Some airlines do even numbers for flight coming into a hub city, and odd numbers for flights departing a hub. Normally the longer-haul flights have a shorter flight number (one or two digits), while shorter-haul and regional flights have three or four digits. Many airlines have designated numbers higher than 5000 as codeshare flights. Lots of airlines that fly to Asia keep an "8" in the flight number somewhere because that number is lucky. Our airline also does not reuse flight numbers that were involved in an accident that caused a loss of life.
So there are a lot of things involved, and ultimately its up to the airline.