exercise 5.7
added a proportional sampling function