fix rand loop