Skip to content

Instantly share code, notes, and snippets.

@mikejoyceio
Last active August 29, 2015 14:15
Show Gist options
  • Save mikejoyceio/5e31d34c647b6ceef5fc to your computer and use it in GitHub Desktop.
Save mikejoyceio/5e31d34c647b6ceef5fc to your computer and use it in GitHub Desktop.
Python function that returns a specified number of random items from an iterable
import random
def random_items(itr, int):
list = []
count = 0
while count < int:
rand = random.choice(itr)
list.append(rand)
count += 1
return list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment