CHAPEL HILL, N.C. (AP) _ A gunman opened fire near the University of North Carolina on Thursday, killing a student and a bicyclist, and peppering cars and the post office with fire from his high-powered rifle.

The man began shooting randomly as he walked along a downtown street around 2 p.m., striking a police officer and a student who escaped unharmed when the bullet ricocheted off his keys.

The gunman was shot in the legs by police, then tackled by a bystander who was shot in the struggle. All three of the wounded were taken to the hospital; none suffered life-threatening injuries, authorities said.

One man was gunned down in front of a sorority house, and a bicyclist was killed a half-block away on the steps of the rooming house where he lived. Police said the man near the sorority house was a student and it wasn't immediately clear if the other victim was also. Police weren't releasing the victims' names pending notification of their families.

``He was shooting at me, he was shooting at random, and he was shooting at anybody he saw,'' said Bob Epting, 50, an attorney in Chapel Hill. ``He looked like he was on his way to his own death.''

The gunman worked his way up to the post office building across the street from the 200-year-old University of North Carolina at Chapel Hill.

Orange County District Attorney Carl Fox said the man fired 10 to 15 rounds from a semiautomatic M-1, including several into the back of the post office building, which also contains his offices and a courtroom.

``This came up like a sudden storm,'' grocery store owner Ed Donegan said. ``There was a tremendous amount of shooting.''

The gunman was identified as Wendell Williamson, 26, a third-year law student, according to The News & Observer of Raleigh and The Herald-Sun of Durham. Police contacted by The Associated Press refused to confirm his identity.

Jason Howard, a doctoral candidate in microbiology, said he encountered the gunman walking down the street. The gunman was carrying what appeared to be a high-caliber rifle and a camouflage jacket, he said.

``He looked right at me,'' Howard said. ``I was scared.''

Howard said the gunman fired at him, but the bullet went through his pants and ricocheted off his keys. He was not hurt.

The gunman shot and killed a bicyclist trying to get out of harm's way, said witness Matt Mesmer. The bicyclist's body was sprawled on the steps of a rooming house, about a half-block from the post office.

The student's body fell in front of a sorority house. A backpack stuck out from under a sheet police used to cover his body.

Two police cars were hit by bullets three or four times each, and a female officer in one car was shot in the left hand. Two civilian cars also were hit.

After the killings, the gunman hid in a doorway, then came out and started firing at police, said Chris Pierson, a university senior and a bartender at the nearby Tammany Hall bar. The gunman fell after being hit in the legs by police, but continued firing, Pierson said.

The bar's manager, William Leone, snuck up on the gunman, tackling him when he stopped shooting to change the clip, Pierson said.

In the process, Leone, a former Marine, was shot in the shoulder, said Brian Rathjen, owner of the Anchor Bar. ``He's the hero,'' Rathjen said.

One of the oldest parts of the college campus borders the main road, Franklin Street, a block away from the shooting. The school has about 24,400 students.

Authorities offered no motive.

``What happened up there is not something that any reasonable person could understand,'' Police Chief Ralph Pendergraph said.

``This is not what you would expect in our community, but where would you expect it?''