Lord Uist made the comment during the sentencing of Denis Duffy, 31, who robbed a Chinese restaurant on December 29, 2011, in Cumbernauld, North Lanarkshire.
The judge spoke moments after hearing how Duffy, who has 14 previous convictions, held a knife to Rory Chan, punched him and tried to rob a cash register.
A report which had been prepared for the court on Duffy's character recommended he be given a non-custodial sentence.
However, Lord Uist disagreed and jailed Duffy for four years and eight months. He was also placed on supervision by the authorities for a period of four years following his release from prison.
Lord Uist added: "In light of your criminal record and the circumstances of the crime for which you now appear in this court, I am driven to the conclusion the social worker who assessed you as presenting with a minimum level of criminogenic risks and as suitable for a community-based disposal had taken leave of her senses when she made those assessments.
"On the basis of your criminal history and the commission of this crime, I have no hesitation in coming to the view you present a clear danger to the safety of the public and an extended sentence is called for in this case in order to protect the public from serious harm for you."
The comments emerged following a hearing at the High Court in Edinburgh.
Duffy, a prisoner of HMP Addiewell, in West Lothian, appeared for sentencing. He had been convicted of armed robbery at an earlier hearing.
On that occasion, the court heard how Duffy visited the Oriental Express in Glencryan Road, Cumbernauld, at 10pm on December 29.
He confronted Mr Chan with a blade and tried to take the store's cash register.
However, Mr Chan and a female employee refused to hand over the till prompting Duffy to flee empty-handed.
Sentence was deferred and Lord Uist ordered social workers to interview Duffy so the court could gain information to inform its judgment.
Despite having seven convictions for assault and seven convictions for breach of the peace, the social worker who interviewed Duffy recommended he be given community service.
This recommendation came despite the fact Duffy had appeared in the High Court before and been given two custodial terms on previous occasions.
Yesterday, Lord Uist told the court he was unhappy with the recommendation.
He told Duffy: "You are now 31 years old. You have a deplorable criminal record dating from February 1999 to June 2009.
"I note in particular your history of problems with alcohol and gambling. Had you been convicted by a jury after trial the custodial term of your sentence would have been seven years imprisonment.
"In view of the stage at which you pleaded guilty that sentence will be discounted to four years eight months imprisonment."
Contextual targeting label: