Replace rand with sample