fixex type check/adds docstring for random_index