'Generate a user with a random username and password.'

def generate(self, request, **kwargs):

    for _ in range(10):
        digits = random.randint(100, 10000)
        if (digits in self.number_blacklist):
            continue
        username = 'buddy{}'.format(digits)
        if (not User.objects.filter(username=username).exists()):
            break
    else:
        return Response({'error': 'Unable    to    generate    username.'}, status=500)
    password = ''.join((random.choice(letters) for _ in range(10)))
    display_name = ('B' + username[1:])
    u = User.objects.create(username=username)
    u.set_password(password)
    u.settings.create(name='autogenerated', value='true')
    u.save()
    p = Profile.objects.create(user=u, name=display_name)
    request.user = u
    (token, _) = Token.objects.get_or_create(user=u)
    serializer = ProfileSerializer(instance=p, context={'request': request})
    return Response({'user': serializer.data, 'password': password, 'token': token.key})
