知道代码,改了一下反推种子数:
import random
def key(num):
for _ in range(num):
keySn = []
for i in range(5):
s = ''
characters = 'BCEFGHJKMPQRTVWXY2346789'
for i in range(5):
s = s + random.choice(characters)
keySn.append(s)
key = '-'.join(keySn)
if key[:5]=='RMY9C':
print(n,key)
if __name__ == '__main__':
num = 1
for n in range(100000000): #先测到1亿看看
if n%1000000==0: #每百万打印一下,好知道程序在跑
print(n)
random.seed(n))
key(num)
得到这些:
1853826 RMY9C-WB794-6VEVX-TQP4E-XPECB
2272267 RMY9C-GCYPW-CGKBC-3GQJP-V3WHE
17242826 RMY9C-ERJYV-QGJ8R-79HCM-72GEB
20629002 RMY9C-Q2R73-9BPVK-7XV38-CYY2F
24629929 RMY9C-YXGFK-JKFT4-FX2BH-WKPKR
61168388 RMY9C-CMBHG-9G78Q-KHBBG-Y2E34
63851621 RMY9C-GK3QQ-G6QTR-FQBWV-8YBVQ
68897327 RMY9C-RFPQ9-XQF4P-FWQQE-27PEK
81383307 RMY9C-3KMPY-6VVGQ-68HGM-MH6VC
87790333 RMY9C-C9H2X-944K6-M83B4-KWV29
93063340 RMY9C-FE2FV-PF479-FEVJ8-Y62JK
都不对,难道输入了9位以上的种子数?感觉有点BT啊!再分析源码,原来'n = input()',种子不是整数而是字符,改一下:
import random
def key(num):
for _ in range(num):
keySn = []
for i in range(5):
s = ''
characters = 'BCEFGHJKMPQRTVWXY2346789'
for i in range(5):
s = s + random.choice(characters)
keySn.append(s)
key = '-'.join(keySn)
if key[:5]=='RMY9C':
print(n,key)
if __name__ == '__main__':
num = 1
for n in range(100000000):
if n%1000000==0:
print(n)
random.seed(str(n))
key(num)
一运行就有了:
5 RMY9C-YKW36-F342B-JKG6F-X7Y78
原来是字符'5',改一下自己的代码:
import random as r
a=int(input('请输入个数:'))
b=input('请输入随机数种子:')
char='BCEFGHJKMPQRTVWXY2346789'
r.seed(b) #生成随机数种子
for i in range(a): #需要多少个,循环多少次
sn=''
for j in range(25): #序列号25位
if j%5==0 and j//5>0: #每5个字符加一个'-'
sn+='-'
sn+=r.choice(char) #随机选取字符
print(sn)
运行:
请输入个数:3
请输入随机数种子:5
RMY9C-YKW36-F342B-JKG6F-X7Y78
8GVK8-3KTFQ-X2H68-H9VEG-33VR8
PFXCH-283JE-FVG2B-9GWHB-H9679
是你要的结果吧?感觉出题的老师真有点BT,还是你理解错误题目?