Anecdotally, it worked for my uncle. The judge gave him the option to join the Marines or go to prison. He chose the former and he ended up becoming a productive member of society.
[0] - https://www.stripes.com/news/judge-said-army-or-jail-but-mil...
[anecdote] I used to know someone who was an addict. Judge gave her the choice of going on probation for a year, or 45 days in jail. The catch was if she took the probation offer but was picked up for drug offenses in that time, it was an immediate sentence of a year in jail.
She took the 45 days. Better the devil you know than the one you can't control! [/anecdote]