Revised the random-in-range function