At the High Court in Glasgow, William McCulloch, 24, admitted assaulting 56-year-old Alan Wood and attempting to rob him of a sum of cash at William Hill bookmaker's in Nithsdale Road, Glasgow, on June 10.
He also admitted robbing Ladbrokes in the city's West Nile Street of £500 on June 7 after brandishing a mallet.
Judge Lady Stacey yesterday said McCulloch was a danger to the public and ordered him to be monitored in the community for two years after his release.
Advocate depute Paul Kearney, prosecuting, told the court McCulloch, who has convictions for assault, police assault and possession of a knife, has never had a custodial sentence.
The court was told McCulloch entered William Hill as Mr Wood was about to close up for the night.
McCulloch shouted: "Give us your money," before striking Mr Wood on the head with a mallet.
Mr Kearney added: "A struggle ensued during which the accused struck the complainer several more times on the head."
Mr Wood fought back and refused to hand over the keys to the office. He was punched and hit with the mallet again but escaped and ran to a pub for help.
The court heard police found a pair of trousers, a jacket and a mallet dumped in a nearby garden, stained with Mr Wood's blood.
Solicitor advocate Liam O'Donnell, defending, said: "Both offences were committed to fund a serious drug addiction."