The man who fatally stabbed an 18-year-old student with no apparent motive has been sentenced to life in prison.