This content originally appeared on DEV Community and was authored by Vaarun Sinha
In this blog, we will explore the random.shuffle method in python, and implement this method in our password generator project.
So Let's Get Started!
What is the random.shuffle method?
Basically the random.shuffle methods takes in a list like:
[1, 2, 3, 4, 5, 6, 7, 8, 9] and shuffles it like: 2, 1, 5, 6, 8, 9, 4, 7, 3].
Run this code to know more:
Let's implement this in our own project!
In the previous blog, we had a problem:
Now if we print/generate the password every time ,there is a
predictable format, first numbers then special etc..
So for that first let's convert the password into a list:
password = list(numPart + spPart + smallPart + bigPart)
random.shuffle(password)
password_str = ''.join(password)
return password_str
Done! Simple Right?
But what if the user forgets the password and wants to access it? we will build that functionality later on! in the next blog which will come in 2 weeks!
This is the final code for a basic password generator!
So stay tuned!
Happy Coding!
This content originally appeared on DEV Community and was authored by Vaarun Sinha
Vaarun Sinha | Sciencx (2021-11-18T13:53:24+00:00) What is random.shuffle() method in python? How to use it?. Retrieved from https://www.scien.cx/2021/11/18/what-is-random-shuffle-method-in-python-how-to-use-it/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.