[Python] [Beginner] I want to make a random string generator that doesn't alternate numbers in English.

Asked 2 years ago, Updated 2 years ago, 15 views

// Python

import string
import random

English string = string.ascii_letters
Numeric column = string.digits
String Length = 15
Password = ''
For i in range:
// I don't want to alternate numbers with English here, what should I do?
    Password + = random.choice + random.choice
print (password)

python

2022-09-22 10:19

1 Answers

English numerals, English numerals <- You want to prevent this from happening, right?

Try it as below.

In [1]: import string

In [2]: import random

In [3]: seedStr = string.ascii_letters + string.digits

In [4]: ''.join(random.choice(seedStr) for _ in range(15))
Out[4]: 'DNV0MBcQPj3tbmY'

In [5]: ''.join(random.choice(seedStr) for _ in range(15))
Out[5]: 'K3JJR8ZkzJ0AFZ9'


2022-09-22 10:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.