Skip to content

Instantly share code, notes, and snippets.

@metula
Created December 18, 2013 21:54
Show Gist options
  • Save metula/8030508 to your computer and use it in GitHub Desktop.
Save metula/8030508 to your computer and use it in GitHub Desktop.
import random
def generate_name():
""" generate a random first name with 3-6 letters,
space, and family name with 4-8 letters """
first=random.sample(alphabet ,random.randint(3,6))
family=random.sample(alphabet ,random.randint(4,8))
name=str.join("", first) + " " + str.join("", family)
return str.title(name)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
class Student:
def __init__(self):
self.name = generate_name()
self.id = random.randint(2*10**7,6*10**7)
def __repr__(self):
return "<{name}, {id}>".format(**self.__dict__)
def __eq__(self, other):
return self.name == other.name \
and self.id == other.id
def __lt__(self, other):
return self.name < other.name
def is_given_name(self,word):
return self.name.startswith(word+" ")
def students(n):
return [ Student() for i in range(n)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment