Lindsay Lohan must submit to random drug and alcohol testing, and if she flunks she's going back to jail ... according to Judge Elden Fox.
During this morning's court hearing ... Judge Fox imposed the following ground rules for Lindsay's probation:
-- Reside at home until Nov. 1 -- Random drug and alcohol testing twice a week -- Participate in psychotherapy a minimum of 4 days a week -- Attend behavior therapy sessions 2 times a week -- Attend a 12-step program
The judge said if Lindsay flunks her drug and alcohol tests, she'll go to jail for 30 days -- and she cannot leave the state of California without court approval.
Additionally, two counts of being under the influence of cocaine were dismissed.
Outside of court Lindsay's lawyer, Shawn Chapman Holley, said that Lindsay is "looking forward to beginning anew, and having a productive life and schedule."