Read the rstr module documentation, there is an advice to use the SystemRandom to generate more secure random string.
from rstr import Rstr from random import SystemRandom rgen = Rstr(SystemRandom()) pattern = r"[0-9a-zA-Z]{16}" pattern1 = r"\S{16}" print(f"16 long alphanumeric password: {rgen.xeger(pattern)}\n" f"16 long all characters passord: {rgen.xeger(pattern1)}")