This will go through and create every possible permutation of a username with a length of between 4 and 255 characters.
import itertools
# creating file
f = open('usernames.txt', 'w')
# setting character possibilities
chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
# setting lengths
min_length, max_length = 4, 255
# generate every possible combination
for n in range(min_length, max_length+1):
for xs in itertools.product(chrs, repeat=n):
print(''.join(xs))
I am trying to calculate the amount of characters so that I can estimate disk space used. This is my code to count each character. I am looping through each amount of iterations and multiplying it by the number in the range. Can you please double check to make sure that I am correctly looping so that my count is correct?
parent = 62
# setting lengths
min_length, max_length = 4, 255
iterations = []
character_count = []
# generate every possible combination
for i in range(min_length, max_length+1):
iteration = parent ** i
iterations.append(iteration)
for c in iterations:
for i in range(min_length, max_length+1):
characters = c * i
character_count.append(characters)
print(sum(character_count))
I'm not a mathematician, so I'm just hoping I do it right.
1 Answer 1
I may be missing something but it looks as if you should have a quick (or longer) look at the maths:
... create every possible permutation of a username with a length of between 4 and 255 characters
For a length 4 name there are 4 slots, each with 62 possible values. There are thus \$ 62^4 = 14,776,336 \$ possible names.
For length 128, there are \$ 62^{128} \approx 2.6677 ×ばつ 10^{229} \$ possible names.
For length 255, there are \$ 62^{255} \approx 1.1478 ×ばつ 10^{457} \$ possible names.
For comparison, an estimate of the number of atoms in the universe is between \$ 10^{78} \$ and \$ 10^{82} \$.
-
\$\begingroup\$ For another context, my computer takes ~4s to generate the 14,776,336 names of length 4. Assuming a constant time per name (likely an underestimate as the names get longer) it would take ~10**445 years to process all of them... \$\endgroup\$jonrsharpe– jonrsharpe2015年04月29日 09:34:54 +00:00Commented Apr 29, 2015 at 9:34
-
\$\begingroup\$ Epic. I assumed it was something like that, I just wasn't sure. I appreciate it. Thanks! \$\endgroup\$Sienna– Sienna2015年04月29日 18:21:16 +00:00Commented Apr 29, 2015 at 18:21
sum(len_ * (62 ** len_) for len_ in range(4, 256))
, which is... huge (2.97e459
!) and also a factor of 128 away from your answer. \$\endgroup\$