move GenRandomIndex to common