Skip to content

Instantly share code, notes, and snippets.

@cestrand
Created August 16, 2017 07:35
Show Gist options
  • Save cestrand/1466521619658a0c1322dc00257cf1e1 to your computer and use it in GitHub Desktop.
Save cestrand/1466521619658a0c1322dc00257cf1e1 to your computer and use it in GitHub Desktop.
class RandomCollection(UserList):
def get_random(self):
"""Get randomly element from this collection"""
max_it = len(self.data) - 1
return self.data[randint(0, max_it)]
def random_boolean(probability=None):
if probability:
return True if uniform(0, 1) <= probability else False
else:
return True if randint(0, 1) else False
def random_date_between(date1, date2):
delta = date2 - date1
max_days = delta.days
new_date = date1 + timedelta(days=randint(0, max_days))
return new_date.strftime('%Y-%m-%d')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment