corrected randomization routine