Add sample() and unit test.