Continuing the discussion from Cách tạo mật khẩu trong C++:
Code python theo thuật toán mình nêu trên cho bạn tham khảo. Đọc thuật toán rồi chuyển sang C++ bạn muốn. Theo cách này thì không cần duyệt lại chuỗi.
__author__ = 'buithaiminh'
import random
digit = '0123456789'
lowerchar = 'abcdefghijklmnopqrstuvwxyz'
upperchar = lowerchar.upper()
password = ''
for i in range(1, 9):
x = random.randint(0, 2)
y = random.randint(0, 9)
z = random.randint(0, 25)
if x == 1:
password += digit.split()[0][y]
elif x == 2:
password += lowerchar.split()[0][z]
else:
password += upperchar.split()[0][z]
print password