-1

I need to create a function that generates a random password of length n, and seed s. So far i have the following:

def ran_password(n,s):
    chars = string.ascii_lowercase
    return ''.join(random.choice(chars) for x in range(n))

This creates the random password as required, but I'm not sure how to incorporate the seed within my function?

Such that when i run the function ran_password(10,123) it always prints out the same password.

ho_howdy
  • 73
  • 8
  • Possible duplicate of [random.seed(): What does it do?](https://stackoverflow.com/questions/22639587/random-seed-what-does-it-do) – pault Nov 05 '19 at 18:32

1 Answers1

1

Use the random.seed() function.

def ran_password(n,s):
    chars = string.ascii_lowercase
    random.seed(s)
    return ''.join(random.choice(chars) for x in range(n))
Barmar
  • 741,623
  • 53
  • 500
  • 612