Okay, I'm done with making a lot of threads with nooby quesions. Those were just some things in the back of my mind. But that's not the point. Here's a program that generates a random 8 character string. It consists of letters A-Z, a-z, and 1-9. There's 767,544,201,216 possible combinations. It could possibly be used to keep bots\macros from using a program or repeatedly doing something. But enough talking, here's the code:
from random import *
def randstr():
#Generates a random string.
#String consists of numbers 1-9, letters a-z & A-Z.
#Letters and number can be in any order.
#Final generated number stored in "rand" variable.
#767,544,201,216 possible combinations
lower = ("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")
upper = ("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")
ch = randint(1,2)
if ch == 1:
case1 = lower
else:
case1 = upper
del ch
ch = randint(1,2)
if ch == 1:
case2 = lower
else:
case2 = upper
del ch
ch = randint(1,2)
if ch == 1:
case3 = lower
else:
case3 = upper
del ch
ch = randint(1,2)
if ch == 1:
case4 = lower
else:
case4 = upper
del ch
test1x = choice(case1)
test2x = choice(case2)
test3x = choice(case3)
test4x = choice(case4)
test1y = randint(1,9)
test2y = randint(1,9)
test3y = randint(1,9)
test4y = randint(1,9)
strconv1 = str(test1y)
strconv2 = str(test2y)
strconv3 = str(test3y)
strconv4 = str(test4y)
shuffled = [test1x, strconv1, test2x, strconv2, test3x, strconv3, test4x, strconv4]
shuffle(shuffled)
count = 0
for number in shuffled:
if count == 0:
sub_set = number
count = count+1
if count == 8:
rand = sub_set
quit
if count != 0:
if count != 8:
sub_set = sub_set+number
count = count+1
print (rand)
del test1x
del test2x
del test3x
del test4x
del test1y
del test2y
del test3y
del test4y
del strconv1
del strconv2
del strconv3
del strconv4
del shuffled
del count
del rand
del sub_set
del number
input ()
randstr()
I just started python about a week ago and I'm learning a lot! Also, I added the del commands because if it were to be used as a function you wouldn't want to leave variables laying around like that.
EDIT:
I edited it so it del the variables before the input. I don't know why but I just felt like doing it that way.