# Character counter

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

# 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.

• The total number of characters is 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. – jonrsharpe Apr 29 '15 at 9:25
• If you want to see the whole number written out: wolframalpha.com/input/?i=sum+j%2862%5Ej%29%2C+j%3D4+to+255 – jonrsharpe Apr 29 '15 at 10:51

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}$.

• 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... – jonrsharpe Apr 29 '15 at 9:34
• Epic. I assumed it was something like that, I just wasn't sure. I appreciate it. Thanks! – mxplusb Apr 29 '15 at 18:21