Len() function messes up my string generation

I have a code which generates a string, and I used the ‘len()’ function to measure the length of the string. Instead of working properly, and generating 1000 random strings (each one is different), it just generates same string 1000 times. What can be the issue?
Here is the link to the code: Help please! - Pastebin.com

I guarantee you that the problem has nothing to do with the len()

Thank you for posting a pastebin instead of a screen shot.

Creating passwords with the random module is not a very good way to
generate passwords. The random module is designed for repeatable
sequences of pseudo-random values, suitable for games and scientific
modelling where it is important to be able to replicate the same values
as needed. For high-quality passwords and other secrets, you should use
the “secrets” module:


Anything that reduces the amount of randomness in the password, such as
eliminating duplicate characters, can only make the password weaker, not
stronger. If an attacker knows that the password contains no repeating
characters, that cuts down how many possible passwords there are and
makes a brute-force attack easier.

Consider a weak 4 character password, taken from only the digits 0-9. In
other words, a PIN. With no restrictions, there are 10*10*10*10 =
10000 possible PINs. But if you forbid duplicates, then there are only
10*9*9*9 = 7290 PINs. You’ve lost more than a quarter of the
possibilities and made a brute-force attack that much simpler.

Looking more closely at your code, the reason it only generates one
password is because you only ask it to generate one password, and then
you print it over and over again. You have:

passwordgenerator = generate_random_password(random.randint(6, 30), SEQUENCE)

But that’s a misleading name. It’s not a password generator, it’s just a
password, a simple string. The function that generates a password gets
called once, generating a password and storing that string in the
variable that is misleadingly called “passwordgenerator”.

Then you enter the loop:

for num in intnum:
    f.write("[" + str(charcount) + " | RANDOM." + num + "]: " + passwordgenerator + "\n")

Ignore all the other stuff, the square brackets and character count
etc, the same password is written each time. If you want a different
password each time, you need this:

for num in intnum:
    password = generate_random_password(random.randint(6, 30), SEQUENCE)
    f.write("[" + str(charcount) + " | RANDOM." + num + "]: " + password + "\n")

That will give you a different password each time.

But honestly, your password generator is extremely complex. Complex is
not good. Simple is better. See the secrets module.

Thanks for the help! I’ll make sure to check out the secrets module!