import uuid


def generate_prefix_uuid(prefix, length=16):
    """
    创建一个带指定前缀的类有序uuid标识，最小长度8时，测试碰撞概率如下
    Linux 3.10.0-693.17.1.el7.x86_64 
    length=8 100w碰撞0
    length=8 1000w碰撞0
    length=8 1500w碰撞0

    :param prefix: 前缀
    :type prefix: string
    :param length: 随机串长度
    :type length: int
    :returns: UUID
    :rtype: string
    """
    if length < 8 or length > 40:
        raise ValueError('8 <= length <= 40')
    uuid1 = uuid.uuid1().hex
    uuid4 = uuid.uuid4().hex
    uid = ''.join([prefix, uuid1[:8], uuid4[:length - 8]])
    return uid