random sample code