And*_*dre 1 random variation variations
我希望有更好数学能力的人能帮助我找出字符串的长度和字符集的总体可能性.
即[a-f0-9] {6}
这种随机字符模式有哪些可能性?
Ham*_*jan 10
它等于集合中提升到6次幂的字符数.在Python(3.x)解释器中:
>>> len("0123456789abcdef")
16
>>> 16**6
16777216
>>>
Run Code Online (Sandbox Code Playgroud)
编辑1: 为什么1670万?那么,000000 ... 999999 = 10 ^ 6 = 1M,16/10 = 1.6和
>>> 1.6**6
16.77721600000000
Run Code Online (Sandbox Code Playgroud)
*编辑2:*
要在Python中创建列表,请执行:print(['{0:06x}'.format(i) for i in range(16**6)])
但是,这太大了.这是一个更简单,更简短的例子:
>>> ['{0:06x}'.format(i) for i in range(100)]
['000000', '000001', '000002', '000003', '000004', '000005', '000006', '000007', '000008', '000009', '00000a', '00000b', '00000c', '00000d', '00000e', '00000f', '000010', '000011', '000012', '000013', '000014', '000015', '000016', '000017', '000018', '000019', '00001a', '00001b', '00001c', '00001d', '00001e', '00001f', '000020', '000021', '000022', '000023', '000024', '000025', '000026', '000027', '000028', '000029', '00002a', '00002b', '00002c', '00002d', '00002e', '00002f', '000030', '000031', '000032', '000033', '000034', '000035', '000036', '000037', '000038', '000039', '00003a', '00003b', '00003c', '00003d', '00003e', '00003f', '000040', '000041', '000042', '000043', '000044', '000045', '000046', '000047', '000048', '000049', '00004a', '00004b', '00004c', '00004d', '00004e', '00004f', '000050', '000051', '000052', '000053', '000054', '000055', '000056', '000057', '000058', '000059', '00005a', '00005b', '00005c', '00005d', '00005e', '00005f', '000060', '000061', '000062', '000063']
>>>
Run Code Online (Sandbox Code Playgroud)
编辑3: 作为一个功能:
def generateAllHex(numDigits):
assert(numDigits > 0)
ceiling = 16**numDigits
for i in range(ceiling):
formatStr = '{0:0' + str(numDigits) + 'x}'
print(formatStr.format(i))
Run Code Online (Sandbox Code Playgroud)
这将需要一段时间打印numDigits = 6.我建议将此转储到文件,如下所示:
def generateAllHex(numDigits, fileName):
assert(numDigits > 0)
ceiling = 16**numDigits
with open(fileName, 'w') as fout:
for i in range(ceiling):
formatStr = '{0:0' + str(numDigits) + 'x}'
fout.write(formatStr.format(i))
Run Code Online (Sandbox Code Playgroud)