added random index function