changed sample to rand