An Idaho judge ordered a young man not to have sex with anyone before he marries as part of his sentencing for the rape of a child, including the unusual edict as a condition of his eventual probation.

District Court Judge Randy Stoker last week sentenced Cody Herrera, 19, to five to 15 years in prison, but he suspended the sentence for a one-year "rider program," for the rape of a 14-year-old girl.

If Herrera completes the program, the unmarried Twin Falls man will be released on probation, during which he will have to remain celibate, Stoker ordered.

RELATED: Sexual assault case with a controversial sentencing

9 PHOTOS Brock Turner sexual assault case See Gallery Brock Turner sexual assault case Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, leaves the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. (REUTERS/Stephen Lam) Former Stanford student Brock Turner who was sentenced to six months in county jail for the sexual assault of an unconscious and intoxicated woman is shown in this Santa Clara County Sheriff's booking photo taken January 18, 2015, and received June 7, 2016. Santa Clara County Sheriff's Department/Handout via REUTERS ATTENTION EDITORS - THIS IMAGE WAS PROVIDED BY A THIRD PARTY. EDITORIAL USE ONLY Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, leaves the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. REUTERS/Stephen Lam Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, leaves the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. REUTERS/Stephen Lam Santa Clara County Sheriff Laurie Smith speaks to members of the media prior to the release of Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, at the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. REUTERS/Stephen Lam Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, leaves the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. REUTERS/Stephen Lam TPX IMAGES OF THE DAY Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, leaves the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. REUTERS/Stephen Lam An undated photo of Brock Allen Turner is shown in Ohio State General's office website. Courtesy Ohio Attorney General's Office/Handout via REUTERS ATTENTION EDITORS - THIS IMAGE WAS PROVIDED BY A THIRD PARTY. EDITORIAL USE ONLY Brock Turner, the former Stanford swimmer convicted of sexually assaulting an unconscious woman, leaves the Santa Clara County Jail in San Jose, California, U.S. September 2, 2016. REUTERS/Stephen Lam Up Next See Gallery Discover More Like This HIDE CAPTION SHOW CAPTION of SEE ALL BACK TO SLIDE

"If you're ever on probation with this court, a condition of that will be you will not have sexual relations with anyone except who you're married to, if you're married," Stoker told Herrera, The Associated Press reported.

Stoker reportedly included the condition in part because Herrera told investigators he had had 34 sexual partners.

"I have never seen that level of sexual activity by a 19-year-old," Stoker said, according to the Times-News.

Read: All-Girl Band Dropped From Music Festival After Drummer Defends Stanford Rapist

Herrera also allegedly admitted to having fantasies about a 13-year-old girl and said he watched pornography depicting rape, the Times-News reported.

He may also face more sex-related charges, as he allegedly admitted to taking pictures and video of a different underage girl, which he kept on his cell phone, prosecutors said.

But Herrera's attorney, Daniel Brown, said he was in a relationship with the girl, who was 17, which is legal in the state of Idaho.

"However there's an issue concerning apparently either recordings or photographs of that encounter," Brown told the judge, the Times-News reported in September.

Herrera pleaded guilty in March 2015 to the rape of the 14-year-old girl as part of a plea agreement that he would not have to register as a sex offender, authorities said.

Read: Pregnant Through Rape, Women Are Forced To Share Child Custody With Their Attackers

While the Idaho Department of Health and Welfare "did not designate Mr. Herrera as a sexual predator... there seems to be an argument that could be made for that," Stoker said during his sentencing.

The victim's mother told the court she believed Herrera had always intended to have sex with her daughter.

"It was his intent from the beginning to take what he wanted from my 14-year-old child — her virginity," the victim's mother said in a victim-impact statement. "And he stayed around until he got it from her. Cody will never understand what he has done to our family. Cody robbed her of her innocence. He destroyed the child left in her. This can never be returned."