When each traffic light turns from green to red just as a driver approaches it, is it pure chance, or karma? At such moments, it suddenly seems as if there's more to all this than meets the eye. These just can't be random events.

They're not, of course. There is a design to traffic flow, both intelligent and evolving. And sometimes infuriating. When you're at a left-hand turn signal facing three packed lanes of traffic a mile and a half long and you don't get a green arrow, it feels like the game's rigged.

It is. Brian Smith is one of the guys who rigs it.

Maybe that's an unfair way to introduce Smith, a city traffic engineer. He seems like a good man who wants to make people's lives better in small ways, and he seems to have a sense of humor. But he also has the final say on whether you get to the day-care center on time, and what's more, he could mess with you from his laptop at home, wearing nothing but pajama bottoms.

"There are a few of us engineers in the city who have the ability to make changes from our home computers," Smith says. "On weekends or Halloween night, the police will have my phone number and might give me a call and say, 'We're about to close this road,' so I've got to make changes to the other streets where traffic is being diverted to try to accommodate it."

Smith, who prior to beginning work for the city 16 years ago put in nine years as an electronic technician in the Navy, gets help from various technological advances that we all take for granted but have indeed made our lives better in small ways. There are in-ground sensors called "detector loops" that sense the presence of metal (not weight), some of which are sensitive enough to be used on bike lanes, to help achieve a dynamic system of traffic flow. There are centralized, computer-controlled, coordinated systems that are set up so lights "cascade" in sequence, occasionally allowing us to drive for several miles without encountering a single red light. (There's a system on Johnson Street that frustratingly uses this concept to prevent anyone from driving over 25 mph, but that's another story.)

There are, increasingly, video cameras set up at intersections to give engineers the eyes they need to inform their brains and fingers, as they sit at their laptops.

"I can control or update 70% or more of the intersections in Madison, make changes on the fly," Smith says. "But there are only certain places where I can bring up camera views: First and East Wash, First and Johnson, Milwaukee and East Wash, East Wash and Eagan, some of the Beltline. There are some that I can even view from my home, several on University, Midvale, Segoe, Farley, I can't remember them all. We're planning on doing more - it's really a great tool."

There are systems in place, in a few cities abroad, where a computer senses circumstances on the ground and changes stoplight patterns and timing accordingly. That's the next step in traffic engineering. And the reason for all the gadgetry? It's not to mess you up. It has, well, a higher purpose.

"We want to minimize the number of stops and starts the vehicles have to do, which creates more pollution, more burning of gas and more crashes if cars are having to come to a stop when they're not expecting to," Smith says. "We try to set the lights to facilitate movements that we know will be coming."

Efficiency in a traffic system is unbelievably difficult to achieve. One car pulling to a stop at a detector loop somewhere on your trip to the mall can throw a wrench into your cascading green lights. Heavier traffic in one direction can mess up people going the other way. Pedestrians can push the walk light, offsetting any carefully constructed timeline engineers have programmed. A freight train passes through town. Accidents happen, or lightning strikes. Or Rhythm & Booms.

"We have computer models, we can simulate on our computers, we can download changes for the time of day and special events," Smith says. "We just try to do the best timing we can. A lot of things that we do, people don't realize."

Engineers adjust the timing of pedestrian lights to match the width of the road. They keep track of vehicle capacity, so when construction sends cars to a different road, they're ready for the increased flow. They figure out whether taking 10 seconds from a column of traffic's green light will wreck the commute of another column of traffic half a mile away. If a butterfly flaps its wings on Doty Street, the wind is felt on Old Sauk - or worse, on the other side of the Beltline, where in some parts of the city, intersections under the state's purview use a different kind of traffic signal controller. ("I've heard rumors they might switch to ours," Smith says.)

Engineers' carefully calibrated programs are sometimes scuttled by residents who want cars to stop at their lights even when intersections are empty - frustrating! - or by downtown business groups who want lights to favor pedestrians. If you enter the system from a side street in those areas, chances are you're going to hit the first signal and have to wait, even when there's nobody there, Smith says.

"There are times people call us yelling, using four-letter words and stuff, about how we should change it, but there's been some pressure by some neighborhood groups to have certain signals operate that way."

Actually, he wishes people would call more often. "Sometimes somebody calls to tell us there's a big problem, big backups at a particular intersection, and it's been going on about a week, and nobody called us to tell us," Smith says. "If somebody had called us - if it's on a bus route we usually hear about it right away - we would have sent somebody out there to make corrections."

At this moment, the curtain has been pulled back: The god of traffic flow has been revealed as a mere mortal just trying to do his job, against insurmountable odds.

"We maintain 300 traffic signals," Smith says. "We can't see them all every day."