Added random sampling function