Random String in linux by system time
linux, random
Solution
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 shown
- `fold` will wrap it to 30 character width
- `head` makes sure we get only the first line
To 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 seed
- We run it through a few hashes to get a "random" string
- Finally we truncate it to 30 characters
Other ways (including the two I listed above) are available at this page and others if you simply google.
Problem
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?