The high risk teenager, who was 16 at the time, carried out a second knife attack in Edinburgh city centre on a further victim three days after the attempted murder.

A judge at the High Court in Edinburgh told him: “These courts have repeatedly made it clear the use of knives will not be tolerated.”

Lord Burns told the youth, who cannot be identified for legal reasons, that he had admitted two serious assaults with a weapon and pointed out that in the first attack on a complete stranger he had struck nine blows.

Sign up to our daily newsletter The i newsletter cut through the noise Sign up Thanks for signing up! Sorry, there seem to be some issues. Please try again later. Submitting...

A general view of the High Court in Edinburgh.

The judge said that he had to have regard to his welfare as a child but also to the danger he posed and ordered his detention in a young offenders’ institution.

He told the teenager, now aged 17, that he would have faced a sentence of five years’ detention but for his guilty pleas.

Lord Burns also ordered that the knife attacker be monitored and supervised for a further six year period and warned him that if he offended again he will be liable to be returned to prison.

The judge said: “I hope the monitoring and supervision will give you the chance to grow up and be a responsible member of society.”

The youth, who has carried weapons since he was 13, earlier admitted attempting to murder Lorne Graham, 32, at Princes Street on September 1 last year by repeatedly punching him on the head and body and repeatedly striking him on the head, neck and body with a knife to his severe injury, permanent disfigurement and to the danger of his life.

He also admitted stabbing a 17-year-old youth on September 4 at Cockburn Street with a knife to his severe injury, permanent disfigurement and to the danger of his life.

The court heard that Mr Graham had been out for a drink with work colleagues and in the early hours of the morning was walking towards a branch of McDonald’s when he became aware of the teenager making fun of two people sleeping in a doorway and confronted him.

Punches were then thrown and the teenager picked up something from the ground before running off towards the West End.

Mr Graham immediately saw blood on his jumper, hands and around his neck area. He realised he had been stabbed and began shouting for help. Members of the public stopped to help the victim and a 999 call was made.

The victim was taken to Edinburgh Royal Infirmary and found to have four stab wounds to his back, one to his chest and neck and three to his arms. They were all cleaned and stitched.

The second stabbing victim had been out drinking with a friend when they came across the teenager and others and got into a shouting match.

The teenager went into a flat in Cockburn Street and emerged with a kitchen knife and stabbed the youth in the back before he staggered across the street and collapsed. A CT scan showed he sustained an injury to a kidney.

Following today’s sentencing, Detective Sergeant Mark Lumsden from Gayfield CID, said: “Both of these incidents were extremely frightening for the victims and left them with serious injuries.

“The men have shown great courage throughout our investigations and I hope today’s sentence will offer them some comfort as they move forward with their lives.

“These were completely unprovoked and unnecessary attacks inflicted by the teenager who had complete disregard for the lives of the victims.

“Any instances of violent crime will not be tolerated and we will continue to work with our partners in the Crown and Procurator Fiscal service to ensure those responsible are brought before the courts.”

Defence solicitor advocate Ewen Roy told the court that during the first attack the teenager “regrettably completely lost control of his temper”.

He said: “I acknowledge this was a very serious attack with a weapon and would have been terrifying for the complainer.”

He said the teenager was diagnosed with ADHD and added: “He clearly will require a great deal of support going forward.”