fix bug in rnd idx