This seems be a duplicate of Random Sampler iterator function so I will respond in the separate thread