Two men were attacked in Harlem early yesterday by a hammer-wielding gang of thugs, police sources said.

The first victim of the seemingly random violence, Timmie Sampson, 31, was hit in the head with a hammer outside 1370 Fifth Ave., at East 115th Street, at about 12:45 a.m.

Sources said he was set upon by a gang of five or six black males wearing white T-shirts, and that at least one of the goons struck him over the head with a hammer.

Sampson’s girlfriend was with him at the time and took off her shirt to help stem the bleeding, sources said. She then put him in a cab, and he was taken to Mount Sinai Hospital, in stable condition, a neighborhood source said.

At about 1:05 a.m., Daniel Legette, 24, was hit in the head with a hammer at the same location, sources said.

He was taken to St. Luke’s Hospital with head trauma, they added.

It does not appear the attackers knew their victims, and the motive remains unknown, the sources said.