improved random looping