trying to build a random password generator (without library random)

Question:

How do I convert the returned remainder into characters from my list? (trying to build a random password generator)

Here’s what I have so far:

import time

seconds = time.time() 
print(seconds)

x = float(7) 
y = seconds 
print(y % x)

savage = (y % x) 
print(str(savage), type(savage))

list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','!','@','#','$','0','1','2','3','4','5','6','7','8','9']
new = str(list).join(str(savage))

I’m trying to figure out a way to use the returned remainder from (x % y) to print different characters from my list. I’m thinking that a way to convert the returned remainder to characters in my list would be to print a new set of characters each time the program is run since the seconds is always changing with time.

Asked By: fallout0227

||

Answers:

Without using the library random, here’s one way to do it. I’ve used the number itself to generate an index between 0 and 65, to determine the character in lis. However the password length varies between 15 and 18.

import time

lis = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','!','@','#','$','0','1','2','3','4','5','6','7','8','9']

#try to generate 10 random passwords:
for _ in range(10):
    y = time.time() 
    # print(y)
    savage = y % 7
    savage = str(savage).replace('.', '')
    # print(savage)

    pw = ''
    n = len(savage)
    for i in range(n):
        if int(savage[i]) <= 5 and i <= 15:    #max idx is 50+15
            idx = int(savage[i])*10 + i
            pw += lis[idx]
        else:
            idx = (int(savage[i])-5)*10 + i
            pw += lis[idx]
    print(n, pw)

Output:

15 EFQxopKLstYZG@Y
17 EFQxy$qL23O5mHy$K
17 EFQxIJg1MNYPwRIT!
16 EFQHoJUriNEP!xSP
17 EFQHyTUVM3YF!Ro$K
16 EFQHSTABWDOZG@8z
18 EFQHofqriDOFQ@I$qG
16 EFQHoTqViDO5!no$
17 EFQHoJ01iNkl6@Szg
17 EF!dSzghCXOPm@SJA
Answered By: perpetualstudent
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.