Skip to content

Instantly share code, notes, and snippets.

@bergantine
Last active April 10, 2025 19:27
Show Gist options
  • Save bergantine/1119284 to your computer and use it in GitHub Desktop.
Save bergantine/1119284 to your computer and use it in GitHub Desktop.
Python Random Password Generator (One Liner). #python #password
python -c "from random import choice; print ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789%^*(-_=+)') for i in range(32)])"
@ajmeese7
Copy link

For Python 3:

python -c "from random import choice; print(''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789%^*(-_=+)') for i in range(32)]))"

Seems that the link above was taken down, or is private.

@urjeetpatel
Copy link

i re-added the correct link for the gist.

Personally, i feel better if you changed this from from random import choice to from secrets import choice.

In the Docs, it says

The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.
In particular, secrets should be used in preference to the default pseudo-random number generator in the random module, which is designed for modelling and simulation, not security or cryptography.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment