def generate_user(i, user_type):
    exists = True
    while exists:
        print(f"Generating Random {user_type} {i}")
        random_user = RandomUser({'nat': 'us', 'gender': 'male'})
        exists = User.query.filter_by(email=random_user.get_email()).first()
    random_picture = requests.get(random_user.get_picture())
    random_name = secrets.token_hex(8)
    _, extension = os.path.splitext(random_user.get_picture())
    file_name = random_name + extension
    path = os.path.join(app.root_path, "static/profile_pictures", file_name)
    size = 500, 500
    picture = Image.open(BytesIO(random_picture.content))
    picture.thumbnail(size)
    picture.save(path)
    password = bcrypt.generate_password_hash("password").decode("utf-8")
    user = User(user_type=user_type,
                first_name=random_user.get_first_name(),
                last_name=random_user.get_last_name(),
                email=random_user.get_email(),
                password=password,
                picture=file_name)
    if user_type == UserTypes.DRIVER:
        for j in range(0, randint(0, MAX_SPONSORSHIPS)):
            exists = True
            while exists:
                print(f"Generating Random Sponsorship {j} for Random User {i}")
                sponsor_id = randint(1, Sponsor.query.count())
                sponsor = Sponsor.query.get(sponsor_id)
                exists = sponsor in user.all_sponsors()
            sponsorship = Sponsorship()
            sponsorship.driver = user
            sponsorship.sponsor = sponsor
            sponsorship.active = bool(getrandbits(1))
            if sponsorship.active:
                sponsorship.points = randint(0, MAX_POINTS)
            db.session.add(sponsorship)
    elif user_type == UserTypes.STORE_MANAGER:
        sponsor_id = randint(1, Sponsor.query.count())
        user.employer = Sponsor.query.get(sponsor_id)
    db.session.add(user)