# Path: django_core/utils/random_utils.py
# def random_alphanum(length=10, lower_only=False):
#     """
#     Gets a random alphanumeric value using both letters and numbers.
# 
#     :param length: size of the random alphanumeric string.
#     :param lower_only: boolean indicating if only lower case letters should be
#         used.
#     :return: alphanumeric string size of length
# 
#     This function uses all number except for:
# 
#     * 0
#     * 1
# 
#     and uses all letters except for:
# 
#     * lower case "l" (el)
#     * lower and upper case "o" and "O" (oh)
# 
#     For upper and lower cased letters...
#     ------------------------------------
#     Upper and lower cased letters and numbers can be used more than once which
#     leaves the possible combinations as follows:
# 
#         8 numbers used + 49 letters used (upper and lower) = 57 total characters
# 
#     Which leads us to the following equation:
# 
#         57 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         57 ^ 1 = 57
#         57 ^ 2 = 3,249
#         57 ^ 3 = 185,193
#         57 ^ 4 = 10,556,001
#         57 ^ 5 = 601,692,057
#         57 ^ 6 = 34,296,447,249
#         57 ^ 7 = 1,954,897,493,193
#         57 ^ 8 = 111,429,157,112,001
#         57 ^ 9 = 6,351,461,955,384,057
#         57 ^ 10 = 362,033,331,456,891,249
#         ...
# 
#     For lower cased letters...
#     --------------------------
#     Lower cased letters and numbers can be used more than once which leaves the
#     possible combinations as follows:
# 
#         8 numbers used + 24 letters used (lower only) = 32 total characters
# 
#     Which leads us to the following equation:
# 
#         32 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         32 ^ 1 = 32
#         32 ^ 2 = 1,024
#         32 ^ 3 = 32,768
#         32 ^ 4 = 1,048,576
#         32 ^ 5 = 33,554,432
#         32 ^ 6 = 1,073,741,824
#         32 ^ 7 = 34,359,738,368
#         32 ^ 8 = 1,099,511,627,776
#         32 ^ 9 = 35,184,372,088,832
#         32 ^ 10 = 1,125,899,906,842,624
#         ...
# 
#     """
#     character_set = ALPHANUM_LOWER if lower_only else ALPHANUM
#     sample_size = 5
#     chars = random.sample(character_set, sample_size)
# 
#     while len(chars) < length:
#         chars += random.sample(character_set, sample_size)
# 
#     random.shuffle(chars)
#     return ''.join(chars[:length])


import math
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.http.response import Http404
from django.template.defaultfilters import slugify
from django_core.utils.random_utils import random_alphanum

        :param length: length of the token
        :param kwargs: additional filter criteria to check for when looking for
            a unique token.

        """
        return self.get_available_tokens(count=1,
                                         token_length=length,
                                         **kwargs)[0]

    def get_available_tokens(self, count=10, token_length=15, **kwargs):
        """Gets a list of available tokens.

        :param count: the number of tokens to return.
        :param token_length: the length of the tokens.  The higher the number
            the easier it will be to return a list.  If token_length == 1
            there's a strong probability that the enough tokens will exist in
            the db.

        """
        # This is the number of extra tokens to try and retrieve so calls to
        # the db can be limited
        token_buffer = int(math.ceil(count * .05))

        if token_buffer < 5:
            token_buffer = 5

        available = set([])

        while True:

# Path: django_core/utils/random_utils.py
# def random_alphanum(length=10, lower_only=False):
#     """
#     Gets a random alphanumeric value using both letters and numbers.
# 
#     :param length: size of the random alphanumeric string.
#     :param lower_only: boolean indicating if only lower case letters should be
#         used.
#     :return: alphanumeric string size of length
# 
#     This function uses all number except for:
# 
#     * 0
#     * 1
# 
#     and uses all letters except for:
# 
#     * lower case "l" (el)
#     * lower and upper case "o" and "O" (oh)
# 
#     For upper and lower cased letters...
#     ------------------------------------
#     Upper and lower cased letters and numbers can be used more than once which
#     leaves the possible combinations as follows:
# 
#         8 numbers used + 49 letters used (upper and lower) = 57 total characters
# 
#     Which leads us to the following equation:
# 
#         57 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         57 ^ 1 = 57
#         57 ^ 2 = 3,249
#         57 ^ 3 = 185,193
#         57 ^ 4 = 10,556,001
#         57 ^ 5 = 601,692,057
#         57 ^ 6 = 34,296,447,249
#         57 ^ 7 = 1,954,897,493,193
#         57 ^ 8 = 111,429,157,112,001
#         57 ^ 9 = 6,351,461,955,384,057
#         57 ^ 10 = 362,033,331,456,891,249
#         ...
# 
#     For lower cased letters...
#     --------------------------
#     Lower cased letters and numbers can be used more than once which leaves the
#     possible combinations as follows:
# 
#         8 numbers used + 24 letters used (lower only) = 32 total characters
# 
#     Which leads us to the following equation:
# 
#         32 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         32 ^ 1 = 32
#         32 ^ 2 = 1,024
#         32 ^ 3 = 32,768
#         32 ^ 4 = 1,048,576
#         32 ^ 5 = 33,554,432
#         32 ^ 6 = 1,073,741,824
#         32 ^ 7 = 34,359,738,368
#         32 ^ 8 = 1,099,511,627,776
#         32 ^ 9 = 35,184,372,088,832
#         32 ^ 10 = 1,125,899,906,842,624
#         ...
# 
#     """
#     character_set = ALPHANUM_LOWER if lower_only else ALPHANUM
#     sample_size = 5
#     chars = random.sample(character_set, sample_size)
# 
#     while len(chars) < length:
#         chars += random.sample(character_set, sample_size)
# 
#     random.shuffle(chars)
#     return ''.join(chars[:length])


# Path: django_core/db/models/managers.py
import math
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.http.response import Http404
from django.template.defaultfilters import slugify
from django_core.utils.random_utils import random_alphanum


        :param length: length of the token
        :param kwargs: additional filter criteria to check for when looking for
            a unique token.

        """
        return self.get_available_tokens(count=1,
                                         token_length=length,
                                         **kwargs)[0]

    def get_available_tokens(self, count=10, token_length=15, **kwargs):
        """Gets a list of available tokens.

        :param count: the number of tokens to return.
        :param token_length: the length of the tokens.  The higher the number
            the easier it will be to return a list.  If token_length == 1
            there's a strong probability that the enough tokens will exist in
            the db.

        """
        # This is the number of extra tokens to try and retrieve so calls to
        # the db can be limited
        token_buffer = int(math.ceil(count * .05))

        if token_buffer < 5:
            token_buffer = 5

        available = set([])

        while True:

            tokens = [random_alphanum(length=token_length)