Add sampling function.