我正在生成随机数,并尝试将其添加到现有密码中。但是我不知道如何在字符串的前面或后面随机化随机数的位置。
任何方式吗?
这应该可以帮助您入门。
import random
# Reproducible example
random.seed(1)
# Setup
rand_num = 1234
rand_pw = "RandomPassword"
# Get random boolean and insert in front or behind
if bool(random.getrandbits(1)):
print(str(rand_num) + rand_pw)
else:
print(rand_pw + str(rand_num))
生产
RandomPassword1234