I would like to generate a random string (e.g. passwords, user names, etc.). It should be possible to specify the needed length (e.g. 13 chars).
What tools can I use?
|
To generate a random password you can use
Generate 7 passwords of length 13:
As mentioned in the comments, you can avoid reducing entropy by using the
To generate random user names you can use
Generate 7 passwords (user names) of length 13:
|
|||||
|
My favorite way to do it is by using /dev/urandom together with tr to delete unwanted characters for instance to get only numbers and letters:
|
|||||||||||||||||||||
|
@Brandin explained in a comment to another answer how to get at most 100 bytes from
The I'm not aware of any substantial advantages/disadvantages between these two methods. One issue with both methods is that the implementation of
(Unlike |
|||||||||||||||||
|
Here is how, I do it. It generates 10 characters random string. You can optimize it by replacing the "fold", with other string processing tools.
|
|||||
|
Depending on the level of randomness you want, you could simply go with bash's (also
The methods reading directly from
|
|||||||||||||||||||||
|
A super easy and simple (probably more simple than you're looking for) way to achieve this would be to generate a random number in a given range, convert that number to its equivalent ASCII character, and append it to the end of a string. Here's a basic example in Python:
EDIT: added comments, and added code to generate multiple passwords and write them to a file |
|||||
|