Fix a bug in random_sample