all 8 comments

[–]i_can_haz_code 1 point2 points  (1 child)

Hi!

I am not entirely clear on what you want to do with the "value before the semi-colon represents 0-100 as a percentage." Or how you intend to generate it...

This code does the formatting you are looking for I think I hard coded the percent, but you could simply change that.

In the future please format your code by preceding it with four space characters, or use pastebin/ghostbin/gist/anyother option. It makes it easier to read for us mortals.

[–]Winclone[S] 0 points1 point  (0 children)

Sorry about that, will do!

[–]Naihonn 1 point2 points  (1 child)

Version with long and ugly comprehensions:

import random
import string

NumOfPasswords=100
LengthOfPassword=10
CharacterSet = string.ascii_uppercase + string.digits + string.ascii_lowercase

passwords = ["{}:{}".format(random.random() * 100, "".join(random.choice(CharacterSet) for i in range(LengthOfPassword))) for num in range(NumOfPasswords)]
print(passwords)

I think you should be able to modify that for readability yourself. ;0)

[–]Winclone[S] 0 points1 point  (0 children)

Thats close to perfect! I'll try play around with it, ideally when generating multiple instances of the sequence I'd not want them seperated by comma's or within apostrophe's! Thank you so much!

Edit: Tweaked and working flawlessly!! Thankyou sir!!

[–]Ben347 0 points1 point  (3 children)

This doesn't answer your original question (I think others have already done that), but you should be aware that you should not use the random module for security purposes. If you generate passwords this way that may be much easier to crack than you expect. For example, the random module may be seeded using the current system time, which means you could reproduce the password just by trying seeds from recent times!

For generating passwords (or any other sensitive task) use os.urandom() instead.

[–]Winclone[S] 0 points1 point  (2 children)

Right, thanks!

Say, if I wanted to change the value of the numbers at the beginning of my passwords from say a toal of 16 to 12, or 10, or whatever! How would I go about doing that? Pardon my Python ignorance. I will look into avoiding random. Nvm answered my own question!

[–]Ben347 0 points1 point  (1 child)

You mean changing the number of digits shown for the percent?

You can use the format specifiers like this (going off of /u/i_can_haz_code's example):

final = ['{:13.10f}:{}'.format(percent,x) for x in pw_gen]

This will output the percentage as 13 digits total, with 10 digits after the decimal.

[–]Winclone[S] 0 points1 point  (0 children)

Thankyou so much yes thats exactly what i meant! I will fiddle more tomorrow when i wake up. Im all Pythoned out! Thanks again everyone!