I work with Bash. I want to generate randrom string by system time . The length of the unique string must be between 10 and 30 characters.Can anybody help me?
A random string is generated by first generating a stream of random numbers of ASCII values for 0-9, a-z and A-Z characters. All the generated integer values are then converted into their corresponding characters which are then appended to a StringBuffer.
The very first method we can use to generate a random string in bash is md5 checksums. Bash has the $RANDOM variable, which produces a random number. We can pipe this value to md5sum to get a random string. The $RANDOM variable is always random.
The random module in python is used to generate random strings. The random string is consisting of numbers, characters and punctuation series that can contain any pattern. The random module contains two methods random. choice() and secrets.
Maybe you can use uuidgen -t
.
Generate a time-based UUID. This method creates a UUID based on the system clock plus the system's ethernet hardware address, if present.
There are many ways to do this, my favorite one using the urandom
device:
burhan@sandbox:~$ tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
CCI4zgDQ0SoBfAp9k0XeuISJo9uJMt
tr
(translate) makes sure that only alphanumerics are shownfold
will wrap it to 30 character widthhead
makes sure we get only the first lineTo use the current system time (as you have this specific requirement):
burhan@sandbox:~$ date +%s | sha256sum | base64 | head -c30; echo
NDc0NGQxZDQ4MWNiNzBjY2EyNGFlOW
date +%s
= this is our date based seedOther ways (including the two I listed above) are available at this page and others if you simply google.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With