文章目录
- 批量生成6位数字防伪码
- 批量生成25位数字与字母混合产品序列号SN码
批量生成6位数字防伪码
import random
import os
randstr=[]
def mkpath(path):
isexists = os.path.exists(path)
if not isexists:
os.mkdir(path)
incount=input(" 请输入生成防伪码数量:")
while int(incount) <= 0:
incount = input(" 请重新输入生成防伪码数量:")
for j in range(int(incount)):
randfir = ''
for i in range(6):
randfir = randfir + str(random.randint(0,9))
randfir = randfir + "\n"
randstr.append(randfir)
datapath = os.getcwd()
datapath = datapath + "\code"
mkpath(datapath)
datafile = datapath + "\\scode5.txt"
file = open(datafile, 'w')
pdata = ""
wdata = ""
for i in range(len(randstr)):
wdata = str(randstr[i].replace('[', '')).replace(']', '')
wdata = wdata.replace(''''','').replace(''''', '')
file.write(str(wdata))
pdata = pdata + wdata
file.close()
print( pdata )
print( "生成的6位防伪码保存在",datapath )

批量生成25位数字与字母混合产品序列号SN码
type_num="BRM8S"
date="2021:12:28"
date=date.split(":")
year_num=date[0][2:]
month=hex(int(date[1])).replace("0x","")
day=date[2]
date_num=year_num+month+day
start=100
count=int(input("请输入要生成的产品序列号(SN)数量:"))
sn=""
for i in range(count):
num=type_num+date_num+str(start+i).zfill(5)
sn+=num+"\n"
print(sn)
