add a function for data sampling