#coding:utf8
import time
import datetime
import random

def random_str(strlength=32, digit=False):
    str = ''
    if digit:
        chars = '0123456789'
    else:
        chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    length = len(chars) - 1
    for i in range(strlength):
        str += chars[random.randint(0, length)]
    return str


def generate_refund_order_id():
    now = datetime.datetime.now()
    start = now.strftime("%y%m%d%H%M%S")
    end = random.randint(0, 998)
    if end % 2 == 1:
        end -= 1

    id_str = "%s%.3d" % (start, end)
    return id_str


def generate_cashback_order_id():
    now = datetime.datetime.now()
    start = now.strftime("%y%m%d%H%M%S")
    end = random.randint(1, 999)
    if end % 2 == 0:
        end -= 1

    id_str = "%s%.3d" % (start, end)
    return id_str
