Factorise code to get or pop random items from a list.