Created
August 16, 2017 07:35
-
-
Save cestrand/1466521619658a0c1322dc00257cf1e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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