Hack Forums
[Python] [Source] Random String Generator - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] [Source] Random String Generator (/showthread.php?tid=6025531)



[Source] Random String Generator - GREGORY - Nov 16, 2019

Randomizing uppercase, lowercase, symbols, and string length.

https://prnt.sc/pxxzqi
https://prnt.sc/pxyb2f

Code
import string
import random

def string_generator(size):
   chars = string.ascii_uppercase + string.digits + string.ascii_lowercase + '!@#$%^&*()_'
   return ''.join(random.choice(chars) for _ in range(size))

rand = random.randint(0,24)
strings = string_generator(rand)
print(strings)



RE: [Source] Random String Generator - SIM-1866423 - Nov 24, 2019

use string.punctuation for symbol and stuffs mate :) I'm always using this,

Code
''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for i in range(RANGE))



RE: [Source] Random String Generator - Kallu609 - Nov 26, 2019

(Nov 24, 2019 08:02 AM)岩倉 玲音 Wrote:  use string.punctuation for symbol and stuffs mate :) I'm always using this,

Code
''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for i in range(RANGE))

Did you even read the code? Also, why SystemRandom(), it's just basic random string generation function, you don't need to care if it's predictable.